]> git.mxchange.org Git - friendica.git/blobdiff - include/session.php
Merge branch 'rewrites/dbm_is_result' of github.com:Quix0r/friendica into rewrites...
[friendica.git] / include / session.php
index c69a4023176889f441cc27023043e7e2dc67b33d..8aca6cb53d356c37d294e14d8d0e968f93c7021c 100644 (file)
@@ -30,7 +30,7 @@ function ref_session_read($id) {
 
        $r = q("SELECT `data` FROM `session` WHERE `sid`= '%s'", dbesc($id));
 
-       if (dbm::is_result($r)) {
+       if(dbm::is_result($r)) {
                $session_exists = true;
                return $r[0]['data'];
        } else {
@@ -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;
 }