speaking of last else of my code
it does not direct my login page to index.php ? do you think the problem is header() function?
    
    if (empty($_POST)===false){
    $username = $_POST['username'];
    $password = $_POST['password']; 
        if(empty($username)=== true || empty($password)=== true){
            $errors[] = 'You need to enter a user name and password';
        }else if(user_exists($username)===false){
            $errors[] = 'we can\'t find that username. Have you registed?';
        }else if(user_active($username)===false){
            $errors[] = 'You have\'t activated your account ! please check your email and active it';
        }else{
            $login = login($username,$password);
            if($login === false){
                $errors[] = "That username/password combination is not correct";
            }else{                  
                $_SESSION['id'] = $login;
                header('Location:index.php');
                exit();
            }
        }       
        print_r($errors);
    }
?>
 
     
    