Niinii
Niinii

Reputation: 83

how to redirect back to before page

i found this link Redirect with Timer in PHP?

i already try this

<meta http-equiv="refresh" content="5;url=http://yourdomain.com"/>


<?php

// wait 5 seconds and redirect :)
echo "<meta http-equiv=\"refresh\" content=\"5;url=http://yourdomain.com\"/>";

?>

Its work but i want redirect back to previous page, any idea? the algorithm is i change page after 5 seconds and want back at previous page after 5 sec to and continue back.. sorry for my bad english

Upvotes: 4

Views: 8271

Answers (4)

Prasanth Bendra
Prasanth Bendra

Reputation: 32740

Use HTTP_REFERER which will give you the page from where you came to the current page.

$_SERVER['HTTP_REFERER']

ref: http://php.net/manual/en/reserved.variables.server.php

<?php

// wait 5 seconds and redirect :)
echo "<meta http-equiv=\"refresh\" content=\"5;url=".$_SERVER['HTTP_REFERER']."\"/>";

?>

Upvotes: 4

Dipesh Parmar
Dipesh Parmar

Reputation: 27364

You could try redirecting to

sleep(5);
$_SERVER['HTTP_REFERER']

Upvotes: 0

Rab
Rab

Reputation: 35572

Can Be done with Pure javascript

setTimeout(function(){
  window.history.back()
}, 5000);

OR if you want to use php

setTimeout(function(){
  window.location = '<?=$_SERVER['HTTP_REFERER'] ?>'
}, 5000);

Upvotes: 1

Ripa Saha
Ripa Saha

Reputation: 2540

use window.go(-1);

for details help see http://www.w3schools.com/jsref/met_his_go.asp

Upvotes: 1

Related Questions