会话在它应该被

时间:2015-06-30 09:32:31

标签: php

所以我认为我会控制会话何时结束,并且它没有按计划进行。我不确定为什么。

我没有倾倒我的所有代码,而是认为我会分享我认为最相关的内容。如果需要更多,请告诉我:

UserManagement.php:

/// <summary>
/// Determines whether the user is still active, and acts accordingly.
/// </summary>
if(session_status() == PHP_SESSION_ACTIVE)
{
    $secondsOfInactivity = 18000;

    $sessionLife = time() - $_SESSION['LastActive'];
    if($sessionLife > $secondsOfInactivity)
    {
        SignOut();
    }

    //if(time() - $_SESSION['LastActive'] > 180)
    //{
    //    // User has been inactive for 3 minutes. Sign them out.
    //    SignOut();
    //}
    //else
    //{
    //    $_SESSION['LastActive'] = time();
    //}
}

function SignedIn()
{        
    return boolval($_SESSION['SI']) == true ? true : false;
}//...

SignIn.php:

<?php
    session_start();

    require_once 'Configuration.php';
    require_once 'UserManagement.php';

    echo SignedIn() ? 'Hi' : 'Bye';//...

UserManagement.php:

/// <summary>
/// Attempts to return an authenticated user.
/// </summary>
function SignIn($emailAddress, $password)
{
    $user = ORM::for_table('Users')->where_equal('EmailAddress', $emailAddress)->where_equal('Password', sha1($password))->find_one();

    if($user != null)
    {
        $_SESSION['SI'] = true;

        $_SESSION['FirstName'] = $user->get('FirstName');
        $_SESSION['LastName'] = $user->get('LastName');
        $_SESSION['EmailAddress'] = $user->get('EmailAddress');
        $_SESSION['UserID'] = $user->get('UserID');

        $_SESSION['LastActive'] = time();

        $user = null;
    }
    else
    {
        SignOut();
    }

    return $_SESSION['SI'];
}

我遇到的问题是虽然secondsOfInactivity设置为较高的数字,但是当我刷新页面或点击链接时,会话不再处于活动状态且我已注销。我不知道为什么我要退出。

如果我在经过一段时间后删除了破坏会话的代码,我仍然按预期登录。但是为什么它会早点把我赶出去呢?

0 个答案:

没有答案