X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fsession.php;h=055bfcb4ef3cf3ff48e3a6da7b330ed02d35ccf1;hb=1058b28ceabcec802932fc33bb79e6ce7814f945;hp=c69a4023176889f441cc27023043e7e2dc67b33d;hpb=a65479ccfd8cc3f949b16eb81e99c9af328d08d2;p=friendica.git diff --git a/include/session.php b/include/session.php index c69a402317..055bfcb4ef 100644 --- a/include/session.php +++ b/include/session.php @@ -40,6 +40,19 @@ function ref_session_read($id) { 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. + * + * @global bool $session_exists Whether a session with the given id already exists + * @global int $session_expire Session expiration delay in seconds + * @param string $id Session ID with format: [a-z0-9]{26} + * @param string $data Serialized session data + * @return boolean Returns false if parameters are missing, true otherwise + */ function ref_session_write($id, $data) { global $session_exists, $session_expire; @@ -51,25 +64,23 @@ function ref_session_write($id, $data) { $default_expire = time() + 300; $memcache = cache::memcache(); - if (is_object($memcache)) { - $memcache->set(get_app()->get_hostname().":session:".$id, $data, MEMCACHE_COMPRESSED, $expire); + $a = get_app(); + if (is_object($memcache) AND is_object($a)) { + $memcache->set($a->get_hostname().":session:".$id, $data, MEMCACHE_COMPRESSED, $expire); return true; } if ($session_exists) { $r = q("UPDATE `session` - SET `data` = '%s' - WHERE `data` != '%s' AND `sid` = '%s'", - dbesc($data), dbesc($data), dbesc($id)); - - $r = q("UPDATE `session` - SET `expire` = '%s' - WHERE `expire` != '%s' AND `sid` = '%s'", - dbesc($expire), dbesc($expire), dbesc($id)); - } else + SET `data` = '%s', `expire` = '%s' + WHERE `sid` = '%s' + AND (`data` != '%s' OR `expire` != '%s')", + dbesc($data), dbesc($expire), dbesc($id), dbesc($data), dbesc($expire)); + } else { $r = q("INSERT INTO `session` SET `sid` = '%s', `expire` = '%s', `data` = '%s'", dbesc($id), dbesc($default_expire), dbesc($data)); + } return true; }