Skip to content

Commit 52f7573

Browse files
authored
Merge pull request #1 from pjsde/fix_session_regenerate
fix issue on session_regenerate.
2 parents 4a3011b + c4c441f commit 52f7573

File tree

4 files changed

+19
-13
lines changed

4 files changed

+19
-13
lines changed

system/Session/Handlers/DatabaseHandler.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,10 @@ public function read($sessionID): string
164164
}
165165

166166
// Needed by write() to detect session_regenerate_id() calls
167-
$this->sessionID = $sessionID;
167+
if(is_null($this->sessionID))
168+
{
169+
$this->sessionID = $sessionID;
170+
}
168171

169172
$builder = $this->db->table($this->table)
170173
->select('data')
@@ -228,11 +231,6 @@ public function write($sessionID, $sessionData): bool
228231
// Was the ID regenerated?
229232
elseif ($sessionID !== $this->sessionID)
230233
{
231-
if (! $this->releaseLock() || ! $this->lockSession($sessionID))
232-
{
233-
return $this->fail();
234-
}
235-
236234
$this->rowExists = false;
237235
$this->sessionID = $sessionID;
238236
}

system/Session/Handlers/FileHandler.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,10 @@ public function read($sessionID): string
187187
}
188188

189189
// Needed by write() to detect session_regenerate_id() calls
190-
$this->sessionID = $sessionID;
190+
if(is_null($this->sessionID))
191+
{
192+
$this->sessionID = $sessionID;
193+
}
191194

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

242244
if (! is_resource($this->fileHandle))
@@ -294,7 +296,7 @@ public function close(): bool
294296
flock($this->fileHandle, LOCK_UN);
295297
fclose($this->fileHandle);
296298

297-
$this->fileHandle = $this->fileNew = $this->sessionID = null;
299+
$this->fileHandle = $this->fileNew = null;
298300

299301
return true;
300302
}

system/Session/Handlers/MemcachedHandler.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,10 @@ public function read($sessionID): string
183183
if (isset($this->memcached) && $this->lockSession($sessionID))
184184
{
185185
// Needed by write() to detect session_regenerate_id() calls
186-
$this->sessionID = $sessionID;
186+
if(is_null($this->sessionID))
187+
{
188+
$this->sessionID = $sessionID;
189+
}
187190

188191
$session_data = (string) $this->memcached->get($this->keyPrefix . $sessionID);
189192
$this->fingerprint = md5($session_data);

system/Session/Handlers/RedisHandler.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,10 @@ public function read($sessionID): string
184184
if (isset($this->redis) && $this->lockSession($sessionID))
185185
{
186186
// Needed by write() to detect session_regenerate_id() calls
187-
$this->sessionID = $sessionID;
187+
if(is_null($this->sessionID))
188+
{
189+
$this->sessionID = $sessionID;
190+
}
188191

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

0 commit comments

Comments
 (0)