IT干货网

php之如何重定向回之前的页面

yjmyzz 2025年05月04日 编程设计 247 0

我找到了这个链接
Redirect with Timer in PHP?

我已经试过了

<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\"/>"; 
 
?> 

它的工作,但我想重定向回上一页,知道吗?算法是我在 5 秒后更改页面并希望在 5 秒后返回上一页并继续返回..
对不起,我的英语不好

请您参考如下方法:

使用 HTTP_REFERER 它将为您提供您来到当前页面的页面。

$_SERVER['HTTP_REFERER'] 

引用: 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']."\"/>"; 
 
?> 


评论关闭
IT干货网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!