mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Fixes SessionComponentTest::testSessionValid. Refactored _hasSession and other erros on php 7
init would always set CakeSession::$_userAgent.
This commit is contained in:
parent
027e32ce00
commit
a59ea13712
1 changed files with 8 additions and 6 deletions
|
@ -143,7 +143,7 @@ class CakeSession {
|
|||
public static function init($base = null) {
|
||||
static::$time = time();
|
||||
|
||||
if (env('HTTP_USER_AGENT')) {
|
||||
if (env('HTTP_USER_AGENT') && !static::$_userAgent) {
|
||||
static::$_userAgent = md5(env('HTTP_USER_AGENT') . Configure::read('Security.salt'));
|
||||
}
|
||||
|
||||
|
@ -202,7 +202,6 @@ class CakeSession {
|
|||
|
||||
$id = static::id();
|
||||
static::_startSession();
|
||||
|
||||
if (!$id && static::started()) {
|
||||
static::_checkValid();
|
||||
}
|
||||
|
@ -218,7 +217,10 @@ class CakeSession {
|
|||
* @return bool True if session has been started.
|
||||
*/
|
||||
public static function started() {
|
||||
return (isset($_SESSION) && (session_id() || (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg')));
|
||||
if (PHP_VERSION >=5.4) {
|
||||
return isset($_SESSION) && (session_status() === PHP_SESSION_ACTIVE);
|
||||
}
|
||||
return isset($_SESSION) && session_id();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -461,10 +463,10 @@ class CakeSession {
|
|||
}
|
||||
|
||||
if (static::started()) {
|
||||
if(session_id() && isset($_SESSION)){
|
||||
if (session_id() && static::_hasSession()){
|
||||
session_write_close();
|
||||
}
|
||||
session_start();
|
||||
}
|
||||
session_destroy();
|
||||
if (isset($_COOKIE[static::_cookieName()])){
|
||||
unset($_COOKIE[static::_cookieName()]);
|
||||
|
@ -591,7 +593,7 @@ class CakeSession {
|
|||
* @return bool
|
||||
*/
|
||||
protected static function _hasSession() {
|
||||
return static::started() || isset($_COOKIE[static::_cookieName()]);
|
||||
return static::started() || isset($_COOKIE[session_name()]) || (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue