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

不重定向到主页(index.php),php,Php,我的代码有问题吗?它可以工作,但不会重定向到my index.php它总是在表单所在的login.php中结束 <?php include 'core/ini.php'; if (empty($_POST) === false) { $username = $_POST ['username']; $password = $_POST ['password']; if (empty ($username) ===

我的代码有问题吗?它可以工作,但不会重定向到my 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);
}
?>

谢谢
编辑*
这是我的login.php

这就是过程的方向。我不知道我的启动会话应该放在哪里,但我不知道为什么它可以正常工作而不会出错。

我想你错过了
会话_start()位于页面顶部,因为您正在存储会话。启动
会话_start()


您的
login()
函数是否也返回TRUE?回显某些内容以检查函数是否按预期返回TRUE。

您必须使用页面顶部的
会话\u start
,我认为您应该在headerlocation之后删除
退出

更改
标题('Location:index.php')
标题('Location:index.php')该空格可能是原因。

发布您的login()函数,可能您在该函数中编写了一些内容我的会话从这里开始
删除
退出(),注释
标题()
首先确保函数返回TRUEmy session在此处开始