刷新页面时$ _Session被破坏

时间:2016-10-13 12:34:03

标签: php jquery ajax session

我在这样的会话变量中存储我的用户名信息,并以session_start()开始页面:

 public function loginStaff($username, $password) {

    // Using real_escape_string to stop SQL injections
     $username = $this->db->real_escape_string($username);
     $password = $this->db->real_escape_string($password);

    // Seeking trough DB with query
    $sql = "SELECT * FROM users WHERE username = '$username' ";
    // Result variabel created
    $result = mysqli_query($this->db, $sql) or die ("Error when SQL query");

    // Fetching the info from Coloumn password to compare with crypted password.

if(mysqli_num_rows($result)) {  
        $row = mysqli_fetch_array($result);
        $hashpassword = $row['password'];
    //Controlling the password that is crypted with Password_hash(),using password_verify

 if(password_verify($password, $hashpassword)) {
            $_SESSION['username'] = $username;  

   // THIS IS SHOWING THE RIGHT VALUE BEFORE REFRESH!  
   var_dump($_SESSION['username']); 

 } else {
            echo "Password not correct";
         }
    } else {
        echo "Username not correct";
    }
}

这是我的Jquery ajax代码,在我按下登录按钮后,我的var_dump在我的DIV #ack中显示了正确的值。

$("#loginStaff-btn").on("click", log);      

function log() {

    console.log('Du har klickat');

    // Declaring variables
    var usernameStaff=$("#usernameStaff").val();
    var passwordStaff=$("#passwordStaff").val();

            $.post('calling_login_staff.php', {
                    usernameStaff: usernameStaff,
                    passwordStaff: passwordStaff, },

                        function(data){
                            console.log(data);
                            $("#ack") .html(data);

                        });
                }

但是当我重新加载/刷新浏览器时,会话变量中的值就消失了。

你能帮助我吗?如果我需要提供更多代码,请告诉我,

0 个答案:

没有答案
相关问题