X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fsession.php;h=31024060f3c0c7c1f465a6cee6fde44af8a4c0bf;hb=66902c7956eedba02ea54aea6ea7aa417344ffbb;hp=c69a4023176889f441cc27023043e7e2dc67b33d;hpb=ee5ada6991e4bf8516026c409587e1ad675547d7;p=friendica.git diff --git a/include/session.php b/include/session.php index c69a402317..31024060f3 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; @@ -58,18 +71,15 @@ function ref_session_write($id, $data) { 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; }