Skip to content

Commit 1685333

Browse files
authored
Only initialize the session-storage array when values are populated. (apereo#429) (apereo#430)
Note that the `$_SESSION` array will only stay empty when `phpCAS::client()` is used. `phpCAS::proxy()` will still trigger the creation of `$_SESSION['phpcas']['service_cookies'] as that array currently needs to be passed as a refrence to the `CAS_CookieJar`'s constructor.
1 parent 12667f3 commit 1685333

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

source/CAS/Client.php

+12-5
Original file line numberDiff line numberDiff line change
@@ -973,11 +973,6 @@ public function __construct(
973973
session_start();
974974
phpCAS :: trace("Starting a new session " . session_id());
975975
}
976-
// init phpCAS session array
977-
if (!isset($_SESSION[static::PHPCAS_SESSION_PREFIX])
978-
|| !is_array($_SESSION[static::PHPCAS_SESSION_PREFIX])) {
979-
$_SESSION[static::PHPCAS_SESSION_PREFIX] = array();
980-
}
981976
}
982977

983978
// Only for debug purposes
@@ -1198,9 +1193,21 @@ protected function setSessionValue($key, $value)
11981193
{
11991194
$this->validateSession($key);
12001195

1196+
$this->ensureSessionArray();
12011197
$_SESSION[static::PHPCAS_SESSION_PREFIX][$key] = $value;
12021198
}
12031199

1200+
/**
1201+
* Ensure that the session array is initialized before writing to it.
1202+
*/
1203+
protected function ensureSessionArray() {
1204+
// init phpCAS session array
1205+
if (!isset($_SESSION[static::PHPCAS_SESSION_PREFIX])
1206+
|| !is_array($_SESSION[static::PHPCAS_SESSION_PREFIX])) {
1207+
$_SESSION[static::PHPCAS_SESSION_PREFIX] = array();
1208+
}
1209+
}
1210+
12041211
/**
12051212
* Remove a session value with the given key.
12061213
*

0 commit comments

Comments
 (0)