$ _SESSION不存储值

时间:2017-12-02 02:00:32

标签: php sql session

我是php的初学者,刚刚在2周前开始作为一个大学项目,我在登录页面中与SESSION斗争。当我打印print_r($ SESSION)函数时,它显示为空。这是下面的代码(ps。暂不担心SQL注入)。

其他一切都完美无瑕,错误完美呈现。它的会话值只是空的!

只有建设性的反馈!请记住,我只是在2周前开始,所以请尽量不要太复杂。

<?php
session_start();
include 'dbconnect.php';
$emailerror = $passworderror = "";

if(isset($_POST['submit']))
{


    $email= $_POST["email"];
    $password= $_POST["password"];

    if (empty($email)) {
        $emailerror = "*Email must be entered";
    }

    elseif (!filter_var($email, FILTER_VALIDATE_EMAIL))
    {   
        $emailerror= "*Invalid email address Entered";    
    }

    // To check if email has already been used or if another account with the same email exists
    else{         
        $emailquery = ("SELECT * FROM `Potential_Employee` WHERE `Email` = '$email'");
        $emailcheckresult = mysqli_query($connection, $emailquery);


        if(mysqli_num_rows($emailcheckresult) == 1){            
            $row=mysqli_fetch_assoc($emailcheckresult);

            if (!password_verify($password, $row['Password'])){
                $passworderror = "*Password is incorrect!";
            }
            else{
                $_SESSION['Email'] = $email;
                $_SESSION['logged_in'] = true;
                echo "<script>document.location='EmployeeDashboard.php';</script>";

            }

        }
        else{
            $emailerror = "*Email does not exist";
        }

    }

    if (empty($password)) {
        $passworderror = "*Password must be entered";
    }

    elseif (strlen($password) < 4 )
    {
        $passworderror= "*Password Has to be greater than 8 Characters";
    }

2 个答案:

答案 0 :(得分:-1)

您需要调试SESSION,如下所示:

print_r($_SESSION);

或者

echo '<pre>' . print_r($_SESSION, TRUE) . '</pre>';
// Make second argument TRUE so it will return instead of echo

或者

echo '<pre>';
var_dump($_SESSION);
echo '</pre>';

答案 1 :(得分:-1)

看起来只是一个错字。

使用:

$_SESSION

$SESSION

所以这应该有效:

print_r($_SESSION)

https://www.w3schools.com/php/php_sessions.asp