Skip to content

Commit

Permalink
Add "cookie_path" as shorthand for php.ini's "session.cookie_path" co…
Browse files Browse the repository at this point in the history
…nfig.
  • Loading branch information
ADmad committed Aug 16, 2014
1 parent ec84c26 commit f6590bd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Network/Request.php
Expand Up @@ -159,7 +159,7 @@ public static function createFromGlobals() {
$sessionConfig = Hash::merge(
[
'defaults' => 'php',
'ini' => ['session.cookie_path' => $base ?: '/']
'cookie_path' => $base ?: '/'
],
(array)Configure::read('Session')
);
Expand Down Expand Up @@ -231,7 +231,7 @@ protected function _setConfig($config) {

if (empty($config['session'])) {
$config['session'] = new Session([
'ini' => ['session.cookie_path' => $config['base'] ?: '/']
'cookie_path' => $config['base'] ?: '/'
]);
}

Expand Down
12 changes: 10 additions & 2 deletions src/Network/Session.php
Expand Up @@ -180,8 +180,10 @@ protected static function _defaultConfig($name) {
*
* ### Configuration:
*
* - timeout: The time in minutes the session should be valid for
* - ini: A list of ini directives to change before the session start.
* - timeout: The time in minutes the session should be valid for.
* - cookie_path: The url path for which session cookie is set. Maps to the
* `session.cookie_path` php.ini config.
* - ini: A list of php.ini directives to change before the session start.
* - handler: An array containing at least the `class` key. To be used as the session
* engine for persisting data. The rest of the keys in the array will be passed as
* the configuration array for the engine. You can set the `class` key to an already
Expand All @@ -198,6 +200,12 @@ public function __construct(array $config = []) {
$config['ini']['session.name'] = $config['cookie'];
}

if (isset($config['cookie_path']) &&
!isset($config['ini']['session.cookie_path'])
) {
$config['ini']['session.cookie_path'] = $config['cookie_path'];
}

if (!empty($config['ini']) && is_array($config['ini'])) {
$this->options($config['ini']);
}
Expand Down
2 changes: 2 additions & 0 deletions tests/TestCase/Network/SessionTest.php
Expand Up @@ -113,6 +113,7 @@ public function testSessionConfigIniSetting() {
$_SESSION = null;

$config = array(
'cookie_path' => '/base',
'cookie' => 'test',
'checkAgent' => false,
'timeout' => 86400,
Expand All @@ -126,6 +127,7 @@ public function testSessionConfigIniSetting() {
$this->assertEquals('', ini_get('session.use_trans_sid'), 'Ini value is incorrect');
$this->assertEquals('example.com', ini_get('session.referer_check'), 'Ini value is incorrect');
$this->assertEquals('test', ini_get('session.name'), 'Ini value is incorrect');
$this->assertEquals('/base', ini_get('session.cookie_path'), 'Ini value is incorrect');
}

/**
Expand Down

0 comments on commit f6590bd

Please sign in to comment.