php sessions to authenticate user on login form

前端 未结 7 1730
借酒劲吻你
借酒劲吻你 2020-12-01 07:29

I have the following code designed to begin a session and store username/password data, and if nothing is submitted, or no session data stored, redirect to a fail page.

7条回答
  •  星月不相逢
    2020-12-01 07:30

    Don't use else section in second if statement.

    session_start();
    
    if(isset($_POST['username']) || isset($_POST['password'])) {
    
        $username = $_POST['username'];
    
        $password = $_POST['password'];
    
        $_SESSION['username'] = $username;
    
        $_SESSION['password'] = $password;
    
    }
    
    if(isset($_SESSION['username']) || isset($_SESSION['password'])){
    
        $navbar = "1";
    
        $logindisplay = "0";
    
        $username = $_SESSION['username'];
    
        $password = $_SESSION['password'];
    
    }
    
    $authed = auth($username, $password);
    
    if( $authed == "0" ){
    
        header('Location:http://website.com/fail.php');
    
    }
    

提交回复
热议问题