簡體   English   中英

不重定向到主頁(index.php)

[英]Not redirecting to home page (index.php)

我的代碼有問題嗎? 它可以工作,但它不會重定向到我的index.php,它始終以表單所在的login.php結尾。

    <?php
    include 'core/ini.php';

    if (empty($_POST) === false) {
        $username = $_POST ['username'];
        $password = $_POST ['password'];

        if (empty ($username) === true || empty ($password) === true ) {
            $errors[] = 'You need to enter a username and password!';

        } else if (user_exists($username) === false) {
            $errors[] = 'We can\'t find that username. Have you registered?';
        } else if (user_active($username) === false) {
            $errors[] = 'You haven\'t activated your account! ';
        } else {
            $login = login($username, $password) ;
            if ($login === false) {
                $errors[] = 'That username/password combination is incorrect ';
            } else {
                $_SESSION['user_id'] = $login;
                header('Location :index.php');
                exit();
            }
        }
        print_r($errors);
    }
    ?>

thanks!

EDIT *

this is my login.php 
<?php
include 'core/ini.php';

if (empty($_POST) === false) {
    $username = $_POST ['username'];
    $password = $_POST ['password'];

    if (empty ($username) === true || empty ($password) === true ) {
        $errors[] = 'You need to enter a username and password!';

    } else if (user_exists($username) === false) {
        $errors[] = 'We can\'t find that username. Have you registered?';
    } else if (user_active($username) === false) {
        $errors[] = 'You haven\'t activated your account! ';
    } else {
        $login = login($username, $password) ;
        if ($login === false) {
            $errors[] = 'That username/password combination is incorrect ';
        } else {
            $_SESSION['user_id'] = $login;
            header('Location :index.php');
            exit();
        }
    }
    print_r($errors);
}
?>

這就是流程的去向。 我不知道我應該在哪里開始我的會議,但我不知道為什么它不會出錯。

我想你錯過了session_start(); 由於您正在存儲會話,因此位於頁面頂部。 啟動session_start();

您的login()函數也返回TRUE嗎? 回聲檢查功能是否按預期返回TRUE。

您必須在頁面頂部使用session_start ,我認為應該在標頭定位后刪除exit

更改header('Location :index.php'); header('Location: index.php'); 該空間可能是原因。

暫無
暫無

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

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