Example #1
0
 /**
  * Read session data
  *
  * @param string $sess_id session ID
  *
  * @return mixed session data if exist, false otherwise
  */
 public function read($sess_id)
 {
     $session = $this->query('hGetAll', $this->id($sess_id));
     if (!empty($session)) {
         if ($session['expiry'] > TIME) {
             return $session['data'];
         } else {
             // the session did not have time to get in "stored_sessions" and got out of date, it is necessary to return only settings
             $this->delete($sess_id);
             $session = Session::decode($session['data']);
             return Session::encode(array('settings' => !empty($session['settings']) ? $session['settings'] : array()));
         }
     }
     return false;
 }
Example #2
0
 /**
  * Read session data
  *
  * @param string $sess_id session ID
  *
  * @return mixed session data if exist, false otherwise
  */
 public function read($sess_id)
 {
     $session = db_get_row('SELECT * FROM ?:sessions WHERE session_id = ?s', $sess_id);
     if (!empty($session)) {
         if ($session['expiry'] > TIME) {
             return $session['data'];
         } else {
             // the session did not have time to get in "stored_sessions" and got out of date, it is necessary to return only settings
             db_query('DELETE FROM ?:sessions WHERE session_id = ?s', $sess_id);
             $session = Session::decode($session['data']);
             return Session::encode(array('settings' => !empty($session['settings']) ? $session['settings'] : array()));
         }
     }
     return false;
 }
Example #3
0
 /**
  * Expire session, move it to stored sessions and log out user
  *
  * @param string $sess_id session ID
  * @param array  $session session data
  */
 public static function expire($sess_id, $session)
 {
     $sess_data = Session::decode($session['data']);
     db_query('REPLACE INTO ?:stored_sessions ?e', array('session_id' => $sess_id, 'data' => self::encode(array('settings' => $sess_data['settings'])), 'expiry' => $session['expiry']));
     if (!empty($sess_data['auth'])) {
         fn_log_user_logout($sess_data['auth'], $session['expiry']);
     }
 }
Example #4
0
 /**
  * Garbage collector - move expired sessions to session archive
  *
  * @param int $max_lifetime session lifetime
  *
  * @return boolean always true
  */
 public function gc($max_lifetime)
 {
     // Move expired sessions to sessions storage
     db_query('REPLACE INTO ?:stored_sessions SELECT * FROM ?:sessions WHERE expiry < ?i', TIME);
     $sessions = db_get_array('SELECT * FROM ?:sessions WHERE expiry < ?i', TIME);
     if ($sessions) {
         foreach ($sessions as $entry) {
             fn_log_user_logout($entry, Session::decode($entry['data']));
         }
         // delete old sessions
         db_query('DELETE FROM ?:sessions WHERE expiry < ?i', TIME);
     }
     // Cleanup sessions storage
     db_query('DELETE FROM ?:stored_sessions WHERE expiry < ?i', TIME - SESSIONS_STORAGE_ALIVE_TIME);
     return true;
 }