Skip to content

Commit

Permalink
fix issue on session_regenerate.
Browse files Browse the repository at this point in the history
  • Loading branch information
pjsde committed Oct 2, 2019
1 parent 4a3011b commit c4c441f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
10 changes: 4 additions & 6 deletions system/Session/Handlers/DatabaseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,10 @@ public function read($sessionID): string
}

// Needed by write() to detect session_regenerate_id() calls
$this->sessionID = $sessionID;
if(is_null($this->sessionID))
{
$this->sessionID = $sessionID;
}

$builder = $this->db->table($this->table)
->select('data')
Expand Down Expand Up @@ -228,11 +231,6 @@ public function write($sessionID, $sessionData): bool
// Was the ID regenerated?
elseif ($sessionID !== $this->sessionID)
{
if (! $this->releaseLock() || ! $this->lockSession($sessionID))
{
return $this->fail();
}

$this->rowExists = false;
$this->sessionID = $sessionID;
}
Expand Down
12 changes: 7 additions & 5 deletions system/Session/Handlers/FileHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,10 @@ public function read($sessionID): string
}

// Needed by write() to detect session_regenerate_id() calls
$this->sessionID = $sessionID;
if(is_null($this->sessionID))
{
$this->sessionID = $sessionID;
}

if ($this->fileNew)
{
Expand Down Expand Up @@ -233,10 +236,9 @@ public function read($sessionID): string
public function write($sessionID, $sessionData): bool
{
// If the two IDs don't match, we have a session_regenerate_id() call
// and we need to close the old handle and open a new one
if ($sessionID !== $this->sessionID && (! $this->close() || $this->read($sessionID) === false))
if ($sessionID !== $this->sessionID)
{
return false;
$this->sessionID = $sessionID;
}

if (! is_resource($this->fileHandle))
Expand Down Expand Up @@ -294,7 +296,7 @@ public function close(): bool
flock($this->fileHandle, LOCK_UN);
fclose($this->fileHandle);

$this->fileHandle = $this->fileNew = $this->sessionID = null;
$this->fileHandle = $this->fileNew = null;

return true;
}
Expand Down
5 changes: 4 additions & 1 deletion system/Session/Handlers/MemcachedHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,10 @@ public function read($sessionID): string
if (isset($this->memcached) && $this->lockSession($sessionID))
{
// Needed by write() to detect session_regenerate_id() calls
$this->sessionID = $sessionID;
if(is_null($this->sessionID))
{
$this->sessionID = $sessionID;
}

$session_data = (string) $this->memcached->get($this->keyPrefix . $sessionID);
$this->fingerprint = md5($session_data);
Expand Down
5 changes: 4 additions & 1 deletion system/Session/Handlers/RedisHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,10 @@ public function read($sessionID): string
if (isset($this->redis) && $this->lockSession($sessionID))
{
// Needed by write() to detect session_regenerate_id() calls
$this->sessionID = $sessionID;
if(is_null($this->sessionID))
{
$this->sessionID = $sessionID;
}

$session_data = $this->redis->get($this->keyPrefix . $sessionID);
is_string($session_data) ? $this->keyExists = true : $session_data = '';
Expand Down

0 comments on commit c4c441f

Please sign in to comment.