mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Fixing issue where empty session id's would cause duplicate key errors. Empty session id sessions are no longer saved. Fixes #1450
This commit is contained in:
parent
b0d4951184
commit
cfce0e45d3
2 changed files with 34 additions and 0 deletions
|
@ -751,6 +751,9 @@ class CakeSession extends Object {
|
|||
* @access private
|
||||
*/
|
||||
function __write($id, $data) {
|
||||
if (!$id) {
|
||||
return false;
|
||||
}
|
||||
$expires = time() + Configure::read('Session.timeout') * Security::inactiveMins();
|
||||
$model =& ClassRegistry::getObject('Session');
|
||||
$return = $model->save(array($model->primaryKey => $id) + compact('data', 'expires'));
|
||||
|
|
|
@ -474,4 +474,35 @@ class CakeSessionTest extends CakeTestCase {
|
|||
$this->setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* testReadAndWriteWithDatabaseStorage method
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
function testDatabaseStorageEmptySessionId() {
|
||||
unset($_SESSION);
|
||||
session_destroy();
|
||||
Configure::write('Session.table', 'sessions');
|
||||
Configure::write('Session.model', 'Session');
|
||||
Configure::write('Session.database', 'test_suite');
|
||||
Configure::write('Session.save', 'database');
|
||||
$this->setUp();
|
||||
$id = $this->Session->id();
|
||||
|
||||
$this->Session->id = '';
|
||||
session_id('');
|
||||
|
||||
$this->Session->write('SessionTestCase', 'This is a Test');
|
||||
$this->assertEqual($this->Session->read('SessionTestCase'), 'This is a Test');
|
||||
|
||||
session_write_close();
|
||||
|
||||
unset($_SESSION);
|
||||
ini_set('session.save_handler', 'files');
|
||||
Configure::write('Session.save', 'php');
|
||||
session_id($id);
|
||||
$this->setUp();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue