Skip to content

Commit

Permalink
Re-adding ability to configure the session cookie name
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed May 22, 2014
1 parent c5f1d81 commit f14af4f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Network/Session.php
Expand Up @@ -126,14 +126,12 @@ public static function create($sessionConfig = []) {
protected static function _defaultConfig($name) {
$defaults = array(
'php' => array(
'checkAgent' => false,
'cookie' => 'CAKEPHP',
'ini' => array(
'session.use_trans_sid' => 0,
)
),
'cake' => array(
'checkAgent' => false,
'cookie' => 'CAKEPHP',
'ini' => array(
'session.use_trans_sid' => 0,
Expand All @@ -145,7 +143,6 @@ protected static function _defaultConfig($name) {
)
),
'cache' => array(
'checkAgent' => false,
'cookie' => 'CAKEPHP',
'ini' => array(
'session.use_trans_sid' => 0,
Expand All @@ -159,7 +156,6 @@ protected static function _defaultConfig($name) {
)
),
'database' => array(
'checkAgent' => false,
'cookie' => 'CAKEPHP',
'ini' => array(
'session.use_trans_sid' => 0,
Expand Down Expand Up @@ -201,6 +197,10 @@ public function __construct(array $config = []) {
$config['ini']['session.gc_maxlifetime'] = 60 * $config['timeout'];
}

if (!empty($config['cookie'])) {
$config['ini']['session.name'] = $config['cookie'];
}

if (!empty($config['ini']) && is_array($config['ini'])) {
$this->options($config['ini']);
}
Expand Down
10 changes: 10 additions & 0 deletions tests/TestCase/Network/SessionTest.php
Expand Up @@ -485,4 +485,14 @@ public function testFlashKey() {
$this->assertNull($session->readFlash('foo'));
}

/**
* Tests that the cookie name can be changed with configuration
*
* @return void
*/
public function testSessionName() {
new Session(['cookie' => 'made_up_name']);
$this->assertEquals('made_up_name', session_name());
}

}

0 comments on commit f14af4f

Please sign in to comment.