如何在php中从一个页面重定向到另外一个页面呢?这里列出了三种办法,供参考。
一、用http头信息
也就是用php的header函数。php里的header函数的作用就是向浏览器发出由http协议规定的本来应该通过web服务器的控制指令,例如声明返回信息的类型("context-type: xxx/xxx"),页面的属性("no cache", "expire")等等。
用http头信息重定向到另外一个页面的方法如下:
if (isset($url))
{
header("http/1.1 303 see other");[感谢李凌先生]
header("location: $url");
exit;
}
?>
注意一下,"localtion:"后面有一个空格。
二、用html标记
用html标记,就是用meta的refresh标记,举例如下:
if (!isset($url)) exit;?>
echo "";
echo "location.href=$url";
echo "–>";
?>