问题
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.
回答1:
From 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>
回答2:
As long as they got there by a link you could use
header("Location: " . $_SERVER['HTTP_REFERER']);
回答3:
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.
回答4:
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>";
}
?>
来源:https://stackoverflow.com/questions/7466286/php-browser-go-back-a-page