会话在后端创建和打印,但在前端不起作用

时间:2016-09-02 04:44:53

标签: php jquery session session-variables

我面临一些奇怪的问题。

此问题发生在服务器上。自从过去5-6天后我就遇到了这个问题。直到最后一年,它一直在为我工作。

当我呼叫登录api时,如果用户凭证是正确的,那么我创建一个会话。

这是我的代码:

if ($user){
    if ($user['is_active'] == 1){
        global $user_data;
        $user_data = $user;
        $response["error"] = false;
        $_SESSION['user_data'] = $user; // -- session is create
        print_r($_SESSION); // session is print.

        $_SESSION['is_login'] = 'No';
        unset($_SESSION['sessionX']);
        $response['user_id'] = $user['user_id'];
        $response['name'] = $user['name'];
        $response['email'] = $user['email'];
        $response['apiKey'] = $user['api_key'];
        $response['createdAt'] = $user['created_date'];

    } else {
        $response['error'] = true;
        $response['message'] = 'Your Account is Not Active';
    }
} else {
// user credentials are wrong
    $response['error'] = true;
    $response['message'] = 'Login failed. Incorrect credentials';
}

此部分的print_r:

Array
(
    [slim.flash] => Array
        (
        )

    [db_name] => arcade_intecigar
    [user_data] => Array
        (
            [user_id] => 1
            [name] => zzz
            [email] => zzz@abc.com
            [api_key] => 3fef39209b3d03039cdb81d39566eb66
            [lang_id] => en_US
            [created_date] => 0000-00-00 00:00:00
            [profile_pic] => ""
            [img] => 1461269872mk-ok.png
            [subscription_id] => 20
            [is_active] => 1
            [role_id] => 1
            [delete_permission] => 1
            [phone_number] => +14507013
            [country_code] => 1
            [total_usage_funds] => 0.0024999999441206
            [total_available_funds] => 0.99750000238419
            [paid] => trial
            [currency] => USD
        )

)

登录后,我将我的应用程序重定向到仪表板页面并检查会话是否可用,但会话不可用很奇怪。它总是将我重定向到登录页面。

看下面的代码。

print_r($_SESSION); // it is display a blank
if (!isset($_SESSION['is_login']) && !isset($_SESSION['is_lock'])) {
    echo "<script>window.location='" . SITE_URL . "login.php?redirect=" . $_SERVER['REQUEST_URI'] . "';</script>";
}
if (isset($_SESSION['is_login']) && $_SESSION['is_login'] == 'NO' || $_SESSION['is_login']== 'No') {
    echo "<script>window.location='" . SITE_URL . "login.php?redirect=" . $_SERVER['REQUEST_URI'] . "';</script>";
}   

此部分的print_r:

Array ( [db_name] => arcade_intecigar ) 

1 个答案:

答案 0 :(得分:0)

发生此问题的原因是,在服务器上没有inode内存可用于更多会话创建,据我所知,当在php中创建会话时,会话文件也会创建,因此没有内存可用,这就是为什么会话不是创建。

使用df -i命令了解服务器上的inode内存。

点击此链接了解更多说明:https://www.ivankuznetsov.com/2010/02/no-space-left-on-device-running-out-of-inodes.html