2013-07-30 73 views
0

我想将用户重定向到网站,并在网站上显示“重定向...请稍候”信息。什么是最好的方式来做到这一点?我可以使用HTML和PHP。PHP - 用信息重定向网站

+0

最快的方法是**不**延迟显示他们的重定向消息。 – Quentin

回答

5

试用一下这个:

<!DOCTYPE HTML> 
<html> 
<head> 
    <title>Page Moved</title> 
    <meta http-equiv="refresh" content="3;URL='http://www.example.com/'" />  
</head> 
<body> 
    <p>This page has moved to <a href="http://www.example.com/">www.example.com</a>.</p> 
    <p>You will be redirected within 3 seconds.</p> 
</body> 
</html> 
0

如果你想与php要做到这一点,你可以使用header()函数来发送新的HTTP头,但是这必须在发送到浏览器任何HTML或文本(甚至在声明之前)。

header('Location: '.$newURL); 
die(); 

或者你尝试这样的事情,涉及重定向状态码 - 301,302等

function Redirect($url, $permanent = false) 
{ 
    if (headers_sent() === false) 
    { 
     header('Location: ' . $url, true, ($permanent === true) ? 301 : 302); 
     die(); 
    } 

exit(); 
} 

Redirect('http://www.example.com/', false); 

否则很容易地用HTML

<meta http-equiv="refresh" content="3;URL='http://www.example.com/' /> 

这里content是secods的号码,你想延迟。“

+0

不错,但我两分钟前回答完全一样的东西,聪明的人。 – MightyPork

+0

@MightyPork:我没有看到你的答案,它尚未加载。顺便说一句,我正在编辑我的答案。 –