Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP delay redirect back to a page

Tags:

html

php

Is it possible to timely redirect back a user to the page from where he entered the page ?

if he entered the page from 1.php to ----> 2.php i need a delay redirect to 1.php

redirect always to the page where he entered the other page

like image 813
Sudantha Avatar asked Dec 06 '22 21:12

Sudantha


2 Answers

You could use a meta tag:

<?php if (!empty($_SERVER['HTTP_REFERER'])) { ?>
    <meta http-equiv="refresh" content="2;url=<?php echo $_SERVER['HTTP_REFERER'] ?>">
<?php } ?>

Otherwise, you can use a JavaScript solution:

<head>
<script type="text/javascript">
setTimeout("window.location = '<?php echo $_SERVER['HTTP_REFERER'] ?>'", 2000);
</script>
</head>
like image 145
webbiedave Avatar answered Dec 09 '22 10:12

webbiedave


PHP isn't dynamic (and not clientside) so you can't make timers. You'll have to use a meta tag or JavaScript. See this answer: Redirect with PHP.

like image 42
Midas Avatar answered Dec 09 '22 12:12

Midas