Skip to content

Commit f8ee65d

Browse files
authored
Merge pull request #229 from spirit-q2/fix-session-warning-on-php72-and-above
Fix for `Warning: ini_set(): A session is active...`
2 parents 80ff0d2 + 4d512de commit f8ee65d

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

lib/config/sfFactoryConfigHandler.class.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ public function execute($configFiles)
109109
unset($parameters['database']);
110110
}
111111

112+
if (isset($config['user']['param']['timeout'])) {
113+
$defaultParameters[] = sprintf("'gc_maxlifetime' => %d,", $config['user']['param']['timeout']);
114+
}
115+
112116
$instances[] = sprintf(" \$class = sfConfig::get('sf_factory_storage', '%s');\n \$this->factories['storage'] = new \$class(array_merge(array(\n%s\n), sfConfig::get('sf_factory_storage_parameters', %s)));", $class, implode("\n", $defaultParameters), var_export($parameters, true));
113117
break;
114118

lib/storage/sfSessionStorage.class.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public function initialize($options = null)
6363
'session_cookie_secure' => $cookieDefaults['secure'],
6464
'session_cookie_httponly' => isset($cookieDefaults['httponly']) ? $cookieDefaults['httponly'] : false,
6565
'session_cache_limiter' => null,
66+
'gc_maxlifetime' => 1800,
6667
), $options);
6768

6869
// initialize parent
@@ -90,6 +91,12 @@ public function initialize($options = null)
9091
session_cache_limiter($this->options['session_cache_limiter']);
9192
}
9293

94+
// force the max lifetime for session garbage collector to be greater than timeout
95+
if (ini_get('session.gc_maxlifetime') < $this->options['gc_maxlifetime'])
96+
{
97+
ini_set('session.gc_maxlifetime', $this->options['gc_maxlifetime']);
98+
}
99+
93100
if ($this->options['auto_start'] && !self::$sessionStarted)
94101
{
95102
session_start();

lib/user/sfBasicSecurityUser.class.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This file is part of the symfony package.
55
* (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
66
* (c) 2004-2006 Sean Kerr <sean@code-box.org>
7-
*
7+
*
88
* For the full copyright and license information, please view the LICENSE
99
* file that was distributed with this source code.
1010
*/
@@ -42,7 +42,7 @@ public function clearCredentials()
4242

4343
/**
4444
* Returns the current user's credentials.
45-
*
45+
*
4646
* @return array
4747
*/
4848
public function getCredentials()
@@ -251,12 +251,6 @@ public function initialize(sfEventDispatcher $dispatcher, sfStorage $storage, $o
251251
$this->options['timeout'] = 1800;
252252
}
253253

254-
// force the max lifetime for session garbage collector to be greater than timeout
255-
if (ini_get('session.gc_maxlifetime') < $this->options['timeout'])
256-
{
257-
ini_set('session.gc_maxlifetime', $this->options['timeout']);
258-
}
259-
260254
// read data from storage
261255
$this->authenticated = $storage->read(self::AUTH_NAMESPACE);
262256
$this->credentials = $storage->read(self::CREDENTIAL_NAMESPACE);

0 commit comments

Comments
 (0)