: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* elFinder - file manager for web.
class elFinderSession implements elFinderSessionInterface
* A flag of session started
protected $started = false;
* To fix PHP bug that duplicate Set-Cookie header to be sent
* @see https://bugs.php.net/bug.php?id=75554
protected $fixCookieRegist = false;
* Array of session keys of this instance
protected $keys = array();
* Is enabled base64encode
protected $base64encode = false;
'default' => 'elFinderCaches',
'netvolume' => 'elFinderNetVolumes'
'cookieParams' => array()
* @param array $opts The options
* @return self Instanse of this class
public function __construct($opts)
$this->opts = array_merge($this->opts, $opts);
$this->base64encode = !empty($this->opts['base64encode']);
$this->keys = $this->opts['keys'];
if (function_exists('apache_get_version') || $this->opts['cookieParams']) {
$this->fixCookieRegist = true;
public function get($key, $empty = null)
$session =& $this->getSessionRef($key);
if ($data && $this->base64encode) {
$data = $this->decodeData($data);
} elseif (is_array($empty)) {
} elseif (is_object($empty)) {
} elseif (is_float($empty)) {
} elseif (is_int($empty)) {
if (is_null($data) || ($checkFn && !$checkFn($data))) {
$session = $data = $empty;
set_error_handler(array($this, 'session_start_error'), E_NOTICE | E_WARNING);
// apache2 SAPI has a bug of session cookie register
// see https://bugs.php.net/bug.php?id=75554
// see https://github.com/php/php-src/pull/3231
if ($this->fixCookieRegist === true) {
if ((int)ini_get('session.use_cookies') === 1) {
if (ini_set('session.use_cookies', 0) === false) {
$this->fixCookieRegist = false;
if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
if (session_status() !== PHP_SESSION_ACTIVE) {
$this->started = session_id() ? true : false;
* Get variable reference of $_SESSION
* @param string $key key of $_SESSION array
protected function & getSessionRef($key)
list($cat, $name) = array_pad(explode('.', $key, 2), 2, null);
if (!isset($this->keys[$cat])) {
if (isset($this->keys[$cat])) {
$cat = $this->keys[$cat];
$name = $cat . '.' . $name;
$cat = $this->keys['default'];
if (!isset($_SESSION[$cat])) {
$session =& $_SESSION[$cat];
if (!isset($_SESSION[$cat]) || !is_array($_SESSION[$cat])) {
$_SESSION[$cat] = array();
if (!isset($_SESSION[$cat][$name])) {
$_SESSION[$cat][$name] = null;
$session =& $_SESSION[$cat][$name];
* base64 decode of session val
* @return bool|mixed|string|null
protected function decodeData($data)
if ($this->base64encode) {
if (($data = base64_decode($data)) !== false) {
$data = unserialize($data);
if ($this->fixCookieRegist === true) {
// regist cookie only once for apache2 SAPI
$cParm = session_get_cookie_params();
if ($this->opts['cookieParams'] && is_array($this->opts['cookieParams'])) {
$cParm = array_merge($cParm, $this->opts['cookieParams']);
if (version_compare(PHP_VERSION, '7.3', '<')) {
setcookie(session_name(), session_id(), 0, $cParm['path'] . (!empty($cParm['SameSite'])? '; SameSite=' . $cParm['SameSite'] : ''), $cParm['domain'], $cParm['secure'], $cParm['httponly']);
$allows = array('expires' => true, 'path' => true, 'domain' => true, 'secure' => true, 'httponly' => true, 'samesite' => true);
foreach(array_keys($cParm) as $_k) {
if (!isset($allows[$_k])) {
setcookie(session_name(), session_id(), $cParm);
$this->fixCookieRegist = false;
public function set($key, $data)
$session =& $this->getSessionRef($key);
if ($this->base64encode) {
$data = $this->encodeData($data);
* base64 encode for session val
protected function encodeData($data)
if ($this->base64encode) {
$data = base64_encode(serialize($data));
public function remove($key)
list($cat, $name) = array_pad(explode('.', $key, 2), 2, null);
if (!isset($this->keys[$cat])) {
if (isset($this->keys[$cat])) {
$cat = $this->keys[$cat];
$name = $cat . '.' . $name;
$cat = $this->keys['default'];
if (isset($_SESSION[$cat]) && is_array($_SESSION[$cat])) {
unset($_SESSION[$cat][$name]);
* sessioin error handler (Only for suppression of error at session start)
protected function session_start_error($errno, $errstr)