簡體   English   中英

<meta http-equiv="refresh" content="0; url=http://www.xxxxxxl.com/index.php" />不清爽

[英]<meta http-equiv="refresh" content="0; url=http://www.xxxxxxl.com/index.php" /> is not refreshing

我有一個(非常)簡單的登錄腳本,它運行良好,不知何故,腳本頁面上沒有太多更改,如果有的話,我有以下錯誤:

問題

<meta http-equiv="refresh" content="0; url=http://www.xxxxxx.com/index.php" />

上面的代碼沒有刷新,這意味着用戶在登錄后沒有被重定向。 他/她必須手動刷新頁面才能開始他/她的會話:

在此處輸入圖片說明

從上圖可以看出,登錄成功,但頁面沒有刷新。

請注意使用header("location:")不是這里的選項:

另請注意,我將 Ajax 與表單提交一起使用,以獲取價值...

登錄腳本的一部分:

if ($_SERVER["REQUEST_METHOD"] == "POST") {

    // Do stuff
    if(mysqli_num_rows($result) = 1) {
        while
        {
            // GET session variables
        }//while
        echo 'Success! Logging In....';
        echo '<meta http-equiv="refresh" content="0; url=http://www.xxxxx.com/index.php" />'//now refresh page
    } //if
} //if

奇怪的是,這在上面對我有用,但從昨天起它就停止工作了。

解決方案

這有什么原因不起作用嗎?

我能做些什么來解決這個問題嗎?

有什么替代方法嗎?

您嘗試這樣做的方式是行不通的,因為<meta>標簽應該出現在頁面的<head>部分,而不是正文中。 另外,一旦發送輸出,您就不能使用<meta http-equiv="refresh">或任何其他標頭指令。

嘗試更換這部分:

echo '<meta http-equiv="refresh" content="0; url=http://www.xxxxx.com/index.php" />'

有了這個:

echo '<script>location.href="http://www.xxxxx.com/index.php"</script>';

更好的方法是使用 PHP 更改標題:

header( "refresh:0;url=index.php" ); 而不是您對元標記的echo

您似乎混淆了用於構建站點的所有技術。 最后你只有純 HTML,它應該是這樣的:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="refresh" content="5; url=http://www.google.com/">
    </head>

    <body>
        <p>Redirecting in 5 seconds...</p>
    </body>
</html>

從瀏覽器的角度來看,如何生成此代碼無關緊要。

瀏覽器被設計為對無效 HTML 非常寬容,而您已經將其推到了極限。 然而,Firefox 和 Chrome 都能很好地處理這種情況:

Not redirecting
<meta http-equiv="refresh" content="5; url=http://www.google.com/"></head>

所以一定還有一些你沒有分享的東西。

話雖如此,這是重定向的最奇怪的方式。 我什至不知道人們在 2015 年還在使用它。既然你有 PHP,就利用它:

header('Location: http://www.xxxxxx.com/index.php');
exit;

PHP:打印&#39;

[英]PHP: print '<meta http-equiv=“refresh” content="0;url=' with URL parameters

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM