簡體   English   中英

登錄后的PHP空白頁

[英]PHP blank page after the login

我正在為網站構建CMS。 問題是登錄后出現空白頁,該空白頁一直保留到我點擊刷新為止。 然后將其加載到正確的菜單頁面,除此小細節外,其他所有功能均正常工作。 有解決這個問題的提示嗎? 謝謝,我的代碼如下:

    <?php

session_start();

include_once('../includes/connection.php');
if(isset($_SESSION['logged_in'])) {
    //display index
    ?>

    <html>
    <head>
        <meta charset="UTF-8">
        <title>AdminENG</title>
        <link rel ="stylesheet" href="../assets/style.css"/>
    </head>

        <body>
            <div class="container">
                CMS - ENG
                <ol>

                    <li><a href ="add.php">Add Article</a></li>
                    <li><a href ="delete.php">Delete Article</a></li>
                    <li><a href ="logout.php">Logout</a></li>
                </ol>
            </div>
        </body>
    </html>

    <?php
}
else {
    //display login
    if(isset($_POST['username'], $_POST['password'])) {
        $username = $_POST['username'];
        $password = md5($_POST['password']);

        if (empty($username) || empty($password)) {
            $error = "All fields are required!";
        }
        else {
            $query = $pdo->prepare("SELECT * FROM users WHERE user_name = ? AND user_password = ?");

            $query->bindValue(1, $username);
            $query->bindValue(2, $password);

            $query->execute();

            $num = $query->rowCount();

            if($num == 1) {
                //user entered the correct details
                $_SESSION['logged_in'] = true;

                header('Location: index.php');
                exit();
            }
            else {
                //user entered false details
                $error = "Incorrect details!";
            }
        }
    }

    ?>

    <html>
    <head>
        <title>AdminENG</title>
        <meta charset="UTF-8">
        <link rel ="stylesheet" href="../assets/style.css"/>
    </head>

        <body>
            <div class="container">
                CMS
                <br><br>

                <?php
                if (isset($error)) { ?>
                    <small style="color:#aa0000"><?php echo $error; ?></small>

                <?php } ?>

                <br><br>

                <form action="index.php" method="post">
                    <input type ="text" name="username" placeholder="Username"/>
                    <input type="password" name="password" placeholder="Password"/>
                    <input type="submit" value="Login"/>
                </form>
            </div>
        </body>
    </html>

    <?php
}
?>

您的header()重定向可能無法正常工作。 檢查錯誤日志以查看問題所在。 header()重定向之前,絕對不能將任何字符發送到瀏覽器,否則它將失敗。

我的猜測是<? 在腳本中(如果不是復制/粘貼錯誤)可能會干擾head()重定向。

無論如何,請檢查您的error.log ,看看那里有什么。

對瀏覽器執行html后,將無法使用Header 嘗試替換為: header('Location: index.php');

有了這個:

<script>window.location="index.php";</script>

暫無
暫無

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

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