From f14af4f3dd313f15f1917bd8460bae1998c58d71 Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Thu, 22 May 2014 22:28:48 +0200 Subject: [PATCH] Re-adding ability to configure the session cookie name --- src/Network/Session.php | 8 ++++---- tests/TestCase/Network/SessionTest.php | 10 ++++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/Network/Session.php b/src/Network/Session.php index cfaf3d1d391..e68760df8ca 100644 --- a/src/Network/Session.php +++ b/src/Network/Session.php @@ -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, @@ -145,7 +143,6 @@ protected static function _defaultConfig($name) { ) ), 'cache' => array( - 'checkAgent' => false, 'cookie' => 'CAKEPHP', 'ini' => array( 'session.use_trans_sid' => 0, @@ -159,7 +156,6 @@ protected static function _defaultConfig($name) { ) ), 'database' => array( - 'checkAgent' => false, 'cookie' => 'CAKEPHP', 'ini' => array( 'session.use_trans_sid' => 0, @@ -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']); } diff --git a/tests/TestCase/Network/SessionTest.php b/tests/TestCase/Network/SessionTest.php index 0addeaedcfb..308feb74178 100644 --- a/tests/TestCase/Network/SessionTest.php +++ b/tests/TestCase/Network/SessionTest.php @@ -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()); + } + }