unable to get $_SESSION variable

前端 未结 3 659
难免孤独
难免孤独 2021-01-12 04:56

\"this
In Log-in.php I have

  $email=$_POST[\'email\']; 
  $pass=$_POST[\'         


        
3条回答
  •  不思量自难忘°
    2021-01-12 05:17

    Set this code in login.php :

    session_start();
    $email = $_POST['email'];
    $pass = $_POST['pass'];
    $_SESSION['type'] = 'user';
    $_SESSION['email'] = $email;
    $_SESSION['pass'] = $pass;
    header('location:./connect.php');
    

    And this one in connect.php :

    session_start();
    @mysql_connect('localhost', 'root', '') or die("ERROR in SERVER");
    @mysql_select_db('module') or die("ERROR IN DATABASE");
    $_SESSION['start'] = time(); // taking now logged in time
    if (!isset($_SESSION['expire'])) {
        $_SESSION['expire'] = $_SESSION['start'] + (60 * 60);
    }
    $now = time(); // checking the time now when home page starts
    if ($now > $_SESSION['expire']) {
        session_destroy();
        header('location:./login/login.php');
    }
    if (isset($_SESSION['email']) && !empty($_SESSION['email']) &&
            isset($_SESSION['pass']) && !empty($_SESSION['pass']) &&
            isset($_SESSION['type']) && !empty($_SESSION['type'])) {
    
        $email = $_SESSION['email'];
        $pass = $_SESSION['pass'];
        $type = $_SESSION['type'];
    
        // admin login //
        if ($type == 'admin') {
            $admin = mysql_query("SELECT * FROM `admin` WHERE `email`='$email'");
            $res = mysql_fetch_array($admin);
            if ($email == "" || $pass == "" || $email != $res['email'] || $pass != $res['pass']) {
                session_destroy();
                header('location:./login/login.php');
            }
        }
    
        // user login //
        if ($type == 'user') {
            $user = mysql_query("SELECT `id` FROM `users` WHERE `email`='$email' AND `status`='1'");
            $useres = mysql_fetch_array($user);
            // $trail = $useres['date'];
            //  $time = explode("/",$trail);
            if ($email != $useres['email'] || $pass != $useres['pass']) {
                session_destroy();
                header('location:./login/login.php');
            }
        }
    
        // agent login //
        if ($type == 'agent') {
            $agent = mysql_query("SELECT `id` FROM `sale_agents` WHERE `email`='$email'");
            $agentres = mysql_fetch_array($agent);
            if ($email != $agentres['email'] || $pass != $agentres['pass']) {
                session_destroy();
                header('location:./login/login.php');
            }
        }
    } else {
        header('location:./login/login.php');
    }
    

    I hope this will help you.

提交回复
热议问题