一段时间后,有一个PHP函数可以重定向.我在某个地方看到它但却记不住了.这就像登录后的gmail重定向.请有人提醒我吗?
Ten*_*eff 223
header( "refresh:5;url=wherever.php" );
Run Code Online (Sandbox Code Playgroud)
这是设置的php方式header,它将wherever.php在5秒内重定向到你
请记住,在发送任何实际输出之前,必须通过普通HTML标记,文件中的空行或PHP来调用header().使用include或require,函数或其他文件访问函数读取代码是一个非常常见的错误,并且在调用header()之前输出空格或空行.使用单个PHP/HTML文件时存在同样的问题.(来源php.net)
Ibu*_*Ibu 25
一段时间后你可以使用javascript重定向
setTimeout(function () {
window.location.href= 'http://www.google.com'; // the redirect goes here
},5000); // 5 seconds
Run Code Online (Sandbox Code Playgroud)
小智 16
你可以试试这个:
header('Refresh: 10; URL=http://yoursite.com/page.php');
Run Code Online (Sandbox Code Playgroud)
其中10是秒.
Joh*_*ohn 11
你会想用PHP写出一个元标记.
<meta http-equiv="refresh" content="5;url=http://www.yoursite.com">
Run Code Online (Sandbox Code Playgroud)
不推荐,但有可能.此示例中的5是刷新之前的秒数.
header( "refresh:5;url=wherever.php" );
Run Code Online (Sandbox Code Playgroud)
事实上,您可以像 teneff 所说的那样使用此代码,但您不必一定将标头放在任何发送的输出之前(这将输出“无法重新定位标头....:3 错误”)。
ob_start();要解决此问题,请在输出任何 html 之前使用 php 函数。
要终止 ob,只需ob_end_flush();在没有任何 html 输出后放置即可。
干杯!
| 归档时间: |
|
| 查看次数: |
289817 次 |
| 最近记录: |