X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FCore%2FSession%2FDatabaseSessionHandler.php;h=c4f23b1bfc6424dc3beba1947b0133768b9ea3f2;hb=3a9db3f6373330902a5efe42eb8790c240fba580;hp=d017e2edd23968157caa1e67550b27b591b2e8b5;hpb=ae68196e8d24f859a691774c027cbd8aacdfc463;p=friendica.git diff --git a/src/Core/Session/DatabaseSessionHandler.php b/src/Core/Session/DatabaseSessionHandler.php index d017e2edd2..c4f23b1bfc 100644 --- a/src/Core/Session/DatabaseSessionHandler.php +++ b/src/Core/Session/DatabaseSessionHandler.php @@ -1,95 +1,95 @@ - - */ -class DatabaseSessionHandler extends BaseObject implements SessionHandlerInterface -{ - public function open($save_path, $session_name) - { - return true; - } - - public function read($session_id) - { - if (!x($session_id)) { - return ''; - } - - $session = dba::selectFirst('session', ['data'], ['sid' => $session_id]); - if (DBM::is_result($session)) { - Session::$exists = true; - return $session['data']; - } - logger("no data for session $session_id", LOGGER_TRACE); - - return ''; - } - - /** - * @brief Standard PHP session write callback - * - * This callback updates the DB-stored session data and/or the expiration depending - * on the case. Uses the Session::expire global for existing session, 5 minutes - * for newly created session. - * - * @param string $session_id Session ID with format: [a-z0-9]{26} - * @param string $session_data Serialized session data - * @return boolean Returns false if parameters are missing, true otherwise - */ - public function write($session_id, $session_data) - { - if (!$session_id) { - return false; - } - - if (!$session_data) { - return true; - } - - $expire = time() + Session::$expire; - $default_expire = time() + 300; - - if (Session::$exists) { - $fields = ['data' => $session_data, 'expire' => $expire]; - $condition = ["`sid` = ? AND (`data` != ? OR `expire` != ?)", $session_id, $session_data, $expire]; - dba::update('session', $fields, $condition); - } else { - $fields = ['sid' => $session_id, 'expire' => $default_expire, 'data' => $session_data]; - dba::insert('session', $fields); - } - - return true; - } - - public function close() - { - return true; - } - - public function destroy($id) - { - dba::delete('session', ['sid' => $id]); - return true; - } - - public function gc($maxlifetime) - { - dba::delete('session', ["`expire` < ?", time()]); - return true; - } -} + + */ +class DatabaseSessionHandler extends BaseObject implements SessionHandlerInterface +{ + public function open($save_path, $session_name) + { + return true; + } + + public function read($session_id) + { + if (empty($session_id)) { + return ''; + } + + $session = DBA::selectFirst('session', ['data'], ['sid' => $session_id]); + if (DBA::isResult($session)) { + Session::$exists = true; + return $session['data']; + } + Logger::log("no data for session $session_id", Logger::TRACE); + + return ''; + } + + /** + * @brief Standard PHP session write callback + * + * This callback updates the DB-stored session data and/or the expiration depending + * on the case. Uses the Session::expire global for existing session, 5 minutes + * for newly created session. + * + * @param string $session_id Session ID with format: [a-z0-9]{26} + * @param string $session_data Serialized session data + * @return boolean Returns false if parameters are missing, true otherwise + */ + public function write($session_id, $session_data) + { + if (!$session_id) { + return false; + } + + if (!$session_data) { + return true; + } + + $expire = time() + Session::$expire; + $default_expire = time() + 300; + + if (Session::$exists) { + $fields = ['data' => $session_data, 'expire' => $expire]; + $condition = ["`sid` = ? AND (`data` != ? OR `expire` != ?)", $session_id, $session_data, $expire]; + DBA::update('session', $fields, $condition); + } else { + $fields = ['sid' => $session_id, 'expire' => $default_expire, 'data' => $session_data]; + DBA::insert('session', $fields); + } + + return true; + } + + public function close() + { + return true; + } + + public function destroy($id) + { + DBA::delete('session', ['sid' => $id]); + return true; + } + + public function gc($maxlifetime) + { + DBA::delete('session', ["`expire` < ?", time()]); + return true; + } +}