I want for something like this:
<?php
if($something)
header('Location:javascript:history.go(-2)');
?>
but header('Location:javascript:history.go(-2)');
doesn't work. Any alternatives?
I don't know the page the user was just on, so I can't hardcode the url.
I want for something like this:
<?php
if($something)
header('Location:javascript:history.go(-2)');
?>
but header('Location:javascript:history.go(-2)');
doesn't work. Any alternatives?
I don't know the page the user was just on, so I can't hardcode the url.
Share Improve this question asked Sep 19, 2011 at 3:54 dukevindukevin 23.2k37 gold badges87 silver badges113 bronze badges5 Answers
Reset to default 7From your point of view, i think you might be looking for something like this:
<html><head></head><body>
<?php
if($something){
?>
<script type="text/javascript">
window.history.go(-2);
</script>
<?php
}
?>
</body></html>
As long as they got there by a link you could use
header("Location: " . $_SERVER['HTTP_REFERER']);
You can't use the javascript:
pseudo protocol in a Location
HTTP header. In fact, you really shouldn't be using it at all.
Instead, send the whole URL to the page you want the user to go back to via the Location
HTTP header (if you can) or you could echo the history.back()
though I highly discourage that you do.
As a side note, always exit
after sending the Location
HTTP header. User agents don't have to follow it.
According to your problem .you can use following code in php script at any where..
code:
<?php
if($something){
echo "<script>window.history.back()</script>";
}
?>
if($something) print '<script>window.history.go(-2);</script>';