PHP:浏览器返回页面
我想要这样的东西:
<?php
if($something)
header('Location:javascript:history.go(-2)');
?>
但是 header('Location:javascript:history.go(-2)');
不起作用。还有其他选择吗?
我不知道用户刚刚访问的页面,所以我无法对网址进行硬编码。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
从您的角度来看,我认为您可能正在寻找这样的东西:
From your point of view, i think you might be looking for something like this:
只要他们通过您可以使用的链接到达那里
As long as they got there by a link you could use
您不能在
Location
HTTP 标头中使用javascript:
伪协议。事实上,你根本不应该使用它。相反,通过
Location
HTTP 标头(如果可以的话)将整个 URL 发送到您希望用户返回的页面或者您可以回显历史记录.back()
,尽管我非常不鼓励你这样做。附带说明一下,发送
Location
HTTP 标头后始终退出
。用户代理不必遵循它。You can't use the
javascript:
pseudo protocol in aLocation
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 thehistory.back()
though I highly discourage that you do.As a side note, always
exit
after sending theLocation
HTTP header. User agents don't have to follow it.根据您的问题。您可以在 php 脚本中的任何位置使用以下代码..
代码:
According to your problem .you can use following code in php script at any where..
code: