From 3828a649866a0920ba582a0f1e4f85d0f7fbd011 Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Mon, 26 May 2014 15:32:40 -0500
Subject: [PATCH] session: Properly track new sessions

ee91d179d364b5e1348946c9af33d79a84a01787 introduced a slightly different
tracking system for detecting sessions. Instead of completely disabling the
session system for AJAX and cron requests, it detects if the session is new
or not based on the session_id() and existing data in the session backend.

However, the patch did not correctly determine if a session was new.
Instead, it flagged all session as existing. This patch fixes the detection
of existing session data so that AJAX and cron requests can operate without
writing session data to the backend.
---
 include/class.ostsession.php | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/include/class.ostsession.php b/include/class.ostsession.php
index dc53af14e..4c34fda98 100644
--- a/include/class.ostsession.php
+++ b/include/class.ostsession.php
@@ -77,7 +77,7 @@ class osTicketSession {
     }
 
     function read($id){
-        $this->isnew = true;
+        $this->isnew = false;
         if (!$this->data || $this->id != $id) {
             $sql='SELECT session_data FROM '.SESSION_TABLE
                 .' WHERE session_id='.db_input($id)
@@ -86,10 +86,12 @@ class osTicketSession {
                 return false;
             elseif (db_num_rows($res))
                 list($this->data)=db_fetch_row($res);
+            else
+                // No session data on record -- new session
+                $this->isnew = true;
             $this->id = $id;
         }
         $this->data_hash = md5($id.$this->data);
-        $this->isnew = false;
         return $this->data;
     }
 
-- 
GitLab