Browse Source

Re-adding ability to configure the session cookie name

Jose Lorenzo Rodriguez 12 years ago
parent
commit
f14af4f3dd
2 changed files with 14 additions and 4 deletions
  1. 4 4
      src/Network/Session.php
  2. 10 0
      tests/TestCase/Network/SessionTest.php

+ 4 - 4
src/Network/Session.php

@@ -126,14 +126,12 @@ class Session {
 	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 @@ class Session {
 				)
 			),
 			'cache' => array(
-				'checkAgent' => false,
 				'cookie' => 'CAKEPHP',
 				'ini' => array(
 					'session.use_trans_sid' => 0,
@@ -159,7 +156,6 @@ class Session {
 				)
 			),
 			'database' => array(
-				'checkAgent' => false,
 				'cookie' => 'CAKEPHP',
 				'ini' => array(
 					'session.use_trans_sid' => 0,
@@ -201,6 +197,10 @@ class Session {
 			$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']);
 		}

+ 10 - 0
tests/TestCase/Network/SessionTest.php

@@ -485,4 +485,14 @@ class SessionTest extends TestCase {
 		$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());
+	}
+
 }