예제 #1
0
function buckys_session_start()
{
    $session_id = '';
    session_set_cookie_params(0, "/", "buckysroom.com", false, true);
    //Set Session Handler
    session_set_save_handler('_buckys_session_open', '_buckys_session_close', '_buckys_session_read', '_buckys_session_write', '_buckys_session_destory', '_buckys_session_gc');
    //Change the default session name
    buckys_session_name(SESSION_NAME);
    if (isset($_COOKIE[SESSION_NAME])) {
        if (preg_match('/^[a-zA-Z0-9]+$/', $_COOKIE[SESSION_NAME]) == false) {
            $session_data = session_get_cookie_params();
            setcookie(SESSION_NAME, '', time() - 42000, $session_data['path'], $session_data['domain']);
        } else {
            $session_id = $_COOKIE[SESSION_NAME];
        }
    }
    // if a session ID has been passed to the site, use it
    if (buckys_not_null($session_id)) {
        buckys_session_id($session_id);
    }
    //Session Start
    $session_start_state = session_start();
    if (buckys_not_null($session_id)) {
        if (!isset($_SESSION['session_start_time'])) {
            // If not present, do not use the current session ID
            buckys_session_recreate();
        }
    }
    // If this is a new session, place our server variable in place
    if (!isset($_SESSION['session_start_time'])) {
        $_SESSION['session_start_time'] = time();
    } else {
        // if the session has been expired, recreate the session
        $curr_time = time();
        if ($curr_time - $_SESSION['session_start_time'] > SESSION_LIFETIME) {
            buckys_session_recreate();
            $_SESSION['session_start_time'] = time();
        }
    }
    return $session_start_state;
}
예제 #2
0
/**
 * Session Start
 *
 * @return bool
 */
function buckys_session_start()
{
    $session_id = '';
    if (SITE_USING_SSL) {
        session_set_cookie_params(0, "/", TNB_DOMAIN, true, true);
    } else {
        session_set_cookie_params(0, "/", TNB_DOMAIN);
    }
    // Set Session Handler
    session_set_save_handler('_buckys_session_open', '_buckys_session_close', '_buckys_session_read', '_buckys_session_write', '_buckys_session_destroy', '_buckys_session_gc');
    // Change the default session name
    buckys_session_name(SESSION_NAME);
    // Check if session cookie is set and contains only letters and numbers
    if (isset($_COOKIE[SESSION_NAME])) {
        if (preg_match('/^[a-zA-Z0-9]+$/', $_COOKIE[SESSION_NAME]) == false) {
            $session_data = session_get_cookie_params();
            if (SITE_USING_SSL) {
                setcookie(SESSION_NAME, null, time() - 42000, $session_data['path'], $session_data['domain'], true, true);
            } else {
                setcookie(SESSION_NAME, null, time() - 42000, $session_data['path'], $session_data['domain']);
            }
        } else {
            $session_id = $_COOKIE[SESSION_NAME];
        }
    }
    // If a session ID has been passed to the site, use it
    if (buckys_not_null($session_id)) {
        buckys_session_id($session_id);
    }
    // Session Start
    $session_start_state = session_start();
    // If not present, do not use the current session ID
    if (buckys_not_null($session_id)) {
        if (!isset($_SESSION['session_start_time'])) {
            buckys_session_recreate();
        }
    }
    // Server variable for new sessions. Recreate expired sessions.
    if (!isset($_SESSION['session_start_time'])) {
        $_SESSION['session_start_time'] = time();
    } else {
        $curr_time = time();
        if ($curr_time - $_SESSION['session_start_time'] > SESSION_LIFETIME) {
            buckys_session_recreate();
            $_SESSION['session_start_time'] = time();
        }
    }
    return $session_start_state;
}