Convert static Session class to normal session class
All static Session:: calls (except for checking valid session name) are converted to object type. This Object is passed on to Login, Admin Backend and any other class that needs basic session checking
This commit is contained in:
@@ -15,6 +15,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
{
|
||||
private static $db;
|
||||
private static $log;
|
||||
private static $session;
|
||||
|
||||
/**
|
||||
* start DB conneciton, setup DB, etc
|
||||
@@ -28,6 +29,8 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'The PgSQL extension is not available.'
|
||||
);
|
||||
}
|
||||
// init session
|
||||
self::$session = new \CoreLibs\Create\Session('ACLLoginTest');
|
||||
// logger is always needed
|
||||
// define basic connection set valid and one invalid
|
||||
self::$log = new \CoreLibs\Debug\Logging([
|
||||
@@ -96,7 +99,7 @@ final class CoreLibsACLLoginTest extends TestCase
|
||||
'ACL\Login Tests have not yet been implemented'
|
||||
);
|
||||
|
||||
$login = new \CoreLibs\ACL\Login(self::$db, self::$log);
|
||||
$login = new \CoreLibs\ACL\Login(self::$db, self::$log, self::$session);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,10 +37,10 @@ final class CoreLibsCreateSessionTest extends TestCase
|
||||
'sessionNameGlobals',
|
||||
'/^\w+$/'
|
||||
],
|
||||
'session constant' => [
|
||||
'sessionNameConstant',
|
||||
'c',
|
||||
'sessionNameConstant',
|
||||
'session name default' => [
|
||||
'',
|
||||
'd',
|
||||
'',
|
||||
'/^\w+$/'
|
||||
],
|
||||
];
|
||||
@@ -64,19 +64,22 @@ final class CoreLibsCreateSessionTest extends TestCase
|
||||
$expected_n,
|
||||
$expected_i
|
||||
): void {
|
||||
// NEEDS MOCKING
|
||||
/* $session_id = '';
|
||||
/*
|
||||
// MOCK class for dummy call
|
||||
$session = new \CoreLibs\Create\Session();
|
||||
$session_id = '';
|
||||
unset($GLOBALS['SET_SESSION_NAME']);
|
||||
switch ($type) {
|
||||
case 'p':
|
||||
$session_id = \CoreLibs\Create\Session::startSession($input);
|
||||
$session_id = $session->startSession($input);
|
||||
break;
|
||||
case 'g':
|
||||
$GLOBALS['SET_SESSION_NAME'] = $input;
|
||||
$session_id = \CoreLibs\Create\Session::startSession();
|
||||
$session_id = $session->startSession();
|
||||
break;
|
||||
case 'c':
|
||||
define('SET_SESSION_NAME', $input);
|
||||
$session_id = \CoreLibs\Create\Session::startSession();
|
||||
case 'd':
|
||||
$expected_n = ini_get('session.name');
|
||||
$session_id = \$session->startSession();
|
||||
break;
|
||||
}
|
||||
$this->assertMatchesRegularExpression(
|
||||
@@ -85,11 +88,11 @@ final class CoreLibsCreateSessionTest extends TestCase
|
||||
);
|
||||
$this->assertMatchesRegularExpression(
|
||||
$expected_i,
|
||||
(string)\CoreLibs\Create\Session::getSessionId()
|
||||
(string)$session->getSessionId()
|
||||
);
|
||||
$this->assertEquals(
|
||||
$expected_n,
|
||||
\CoreLibs\Create\Session::getSessionName()
|
||||
$session->getSessionName()
|
||||
);
|
||||
if ($type == 'g') {
|
||||
unset($GLOBALS['SET_SESSION_NAME']);
|
||||
|
||||
@@ -23,14 +23,12 @@ define('USE_DATABASE', true);
|
||||
require 'config.php';
|
||||
// override ECHO ALL FALSE
|
||||
$ECHO_ALL = true;
|
||||
// set session name
|
||||
if (!defined('SET_SESSION_NAME')) {
|
||||
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
|
||||
}
|
||||
// define log file id
|
||||
$LOG_FILE_ID = 'classTest-admin';
|
||||
$SET_SESSION_NAME = EDIT_SESSION_NAME;
|
||||
ob_end_flush();
|
||||
|
||||
$session = new CoreLibs\Create\Session($SET_SESSION_NAME);
|
||||
$log = new CoreLibs\Debug\Logging([
|
||||
'log_folder' => BASE . LOG,
|
||||
'file_id' => $LOG_FILE_ID,
|
||||
@@ -49,7 +47,7 @@ $l10n = new \CoreLibs\Language\L10n(
|
||||
$locale['domain'],
|
||||
$locale['path'],
|
||||
);
|
||||
$backend = new CoreLibs\Admin\Backend($db, $log, $l10n, $locale);
|
||||
$backend = new CoreLibs\Admin\Backend($db, $log, $session, $l10n, $locale);
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: ADMIN BACKEND';
|
||||
print "<!DOCTYPE html>";
|
||||
|
||||
@@ -21,10 +21,6 @@ ob_start();
|
||||
define('USE_DATABASE', false);
|
||||
// sample config
|
||||
require 'config.php';
|
||||
// set session name
|
||||
if (!defined('SET_SESSION_NAME')) {
|
||||
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
|
||||
}
|
||||
// define log file id
|
||||
$LOG_FILE_ID = 'classTest-array';
|
||||
ob_end_flush();
|
||||
|
||||
@@ -20,10 +20,6 @@ ob_start();
|
||||
define('USE_DATABASE', false);
|
||||
// sample config
|
||||
require 'config.php';
|
||||
// set session name
|
||||
if (!defined('SET_SESSION_NAME')) {
|
||||
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
|
||||
}
|
||||
// define log file id
|
||||
$LOG_FILE_ID = 'classTest-autoloader';
|
||||
ob_end_flush();
|
||||
|
||||
@@ -21,10 +21,6 @@ ob_start();
|
||||
define('USE_DATABASE', false);
|
||||
// sample config
|
||||
require 'config.php';
|
||||
// set session name
|
||||
if (!defined('SET_SESSION_NAME')) {
|
||||
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
|
||||
}
|
||||
// define log file id
|
||||
$LOG_FILE_ID = 'classTest-byte';
|
||||
ob_end_flush();
|
||||
|
||||
@@ -21,10 +21,6 @@ ob_start();
|
||||
define('USE_DATABASE', false);
|
||||
// sample config
|
||||
require 'config.php';
|
||||
// set session name
|
||||
if (!defined('SET_SESSION_NAME')) {
|
||||
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
|
||||
}
|
||||
// define log file id
|
||||
$LOG_FILE_ID = 'classTest-colors';
|
||||
ob_end_flush();
|
||||
|
||||
@@ -21,10 +21,6 @@ ob_start();
|
||||
define('USE_DATABASE', false);
|
||||
// sample config
|
||||
require 'config.php';
|
||||
// set session name
|
||||
if (!defined('SET_SESSION_NAME')) {
|
||||
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
|
||||
}
|
||||
// define log file id
|
||||
$LOG_FILE_ID = 'classTest-datetime';
|
||||
ob_end_flush();
|
||||
|
||||
@@ -21,10 +21,6 @@ ob_start();
|
||||
define('USE_DATABASE', false);
|
||||
// sample config
|
||||
require 'config.php';
|
||||
// set session name
|
||||
if (!defined('SET_SESSION_NAME')) {
|
||||
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
|
||||
}
|
||||
// define log file id
|
||||
$LOG_FILE_ID = 'classTest-email';
|
||||
ob_end_flush();
|
||||
|
||||
@@ -21,10 +21,6 @@ ob_start();
|
||||
define('USE_DATABASE', false);
|
||||
// sample config
|
||||
require 'config.php';
|
||||
// set session name
|
||||
if (!defined('SET_SESSION_NAME')) {
|
||||
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
|
||||
}
|
||||
// define log file id
|
||||
$LOG_FILE_ID = 'classTest-encoding';
|
||||
ob_end_flush();
|
||||
|
||||
@@ -21,10 +21,6 @@ ob_start();
|
||||
define('USE_DATABASE', false);
|
||||
// sample config
|
||||
require 'config.php';
|
||||
// set session name
|
||||
if (!defined('SET_SESSION_NAME')) {
|
||||
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
|
||||
}
|
||||
// define log file id
|
||||
$LOG_FILE_ID = 'classTest-datetime';
|
||||
ob_end_flush();
|
||||
|
||||
@@ -21,10 +21,6 @@ ob_start();
|
||||
define('USE_DATABASE', false);
|
||||
// sample config
|
||||
require 'config.php';
|
||||
// set session name
|
||||
if (!defined('SET_SESSION_NAME')) {
|
||||
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
|
||||
}
|
||||
// define log file id
|
||||
$LOG_FILE_ID = 'classTest-hash';
|
||||
ob_end_flush();
|
||||
|
||||
@@ -21,10 +21,6 @@ ob_start();
|
||||
define('USE_DATABASE', false);
|
||||
// sample config
|
||||
require 'config.php';
|
||||
// set session name
|
||||
if (!defined('SET_SESSION_NAME')) {
|
||||
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
|
||||
}
|
||||
// define log file id
|
||||
$LOG_FILE_ID = 'classTest-html';
|
||||
ob_end_flush();
|
||||
|
||||
@@ -21,10 +21,6 @@ ob_start();
|
||||
define('USE_DATABASE', false);
|
||||
// sample config
|
||||
require 'config.php';
|
||||
// set session name
|
||||
if (!defined('SET_SESSION_NAME')) {
|
||||
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
|
||||
}
|
||||
// define log file id
|
||||
$LOG_FILE_ID = 'classTest-image';
|
||||
ob_end_flush();
|
||||
|
||||
@@ -21,10 +21,6 @@ ob_start();
|
||||
define('USE_DATABASE', false);
|
||||
// sample config
|
||||
require 'config.php';
|
||||
// set session name
|
||||
if (!defined('SET_SESSION_NAME')) {
|
||||
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
|
||||
}
|
||||
// define log file id
|
||||
$LOG_FILE_ID = 'classTest-json';
|
||||
ob_end_flush();
|
||||
|
||||
@@ -21,10 +21,6 @@ ob_start();
|
||||
define('USE_DATABASE', false);
|
||||
// sample config
|
||||
require 'config.php';
|
||||
// set session name
|
||||
if (!defined('SET_SESSION_NAME')) {
|
||||
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
|
||||
}
|
||||
// define log file id
|
||||
$LOG_FILE_ID = 'classTest-lang';
|
||||
ob_end_flush();
|
||||
|
||||
@@ -21,13 +21,11 @@ ob_start();
|
||||
define('USE_DATABASE', false);
|
||||
// sample config
|
||||
require 'config.php';
|
||||
// set session name
|
||||
if (!defined('SET_SESSION_NAME')) {
|
||||
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
|
||||
}
|
||||
// define log file id
|
||||
$LOG_FILE_ID = 'classTest-login';
|
||||
$SET_SESSION_NAME = EDIT_SESSION_NAME;
|
||||
// init login & backend class
|
||||
$session = new CoreLibs\Create\Session($SET_SESSION_NAME);
|
||||
$log = new CoreLibs\Debug\Logging([
|
||||
'log_folder' => BASE . LOG,
|
||||
'file_id' => $LOG_FILE_ID,
|
||||
@@ -39,7 +37,7 @@ $log = new CoreLibs\Debug\Logging([
|
||||
'print_all' => $PRINT_ALL ?? false,
|
||||
]);
|
||||
$db = new CoreLibs\DB\IO(DB_CONFIG, $log);
|
||||
$login = new CoreLibs\ACL\Login($db, $log);
|
||||
$login = new CoreLibs\ACL\Login($db, $log, $session);
|
||||
ob_end_flush();
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: LOGIN';
|
||||
|
||||
@@ -21,10 +21,6 @@ ob_start();
|
||||
define('USE_DATABASE', false);
|
||||
// sample config
|
||||
require 'config.php';
|
||||
// set session name
|
||||
if (!defined('SET_SESSION_NAME')) {
|
||||
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
|
||||
}
|
||||
// define log file id
|
||||
$LOG_FILE_ID = 'classTest-math';
|
||||
ob_end_flush();
|
||||
|
||||
@@ -21,10 +21,6 @@ ob_start();
|
||||
define('USE_DATABASE', false);
|
||||
// sample config
|
||||
require 'config.php';
|
||||
// set session name
|
||||
if (!defined('SET_SESSION_NAME')) {
|
||||
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
|
||||
}
|
||||
// define log file id
|
||||
$LOG_FILE_ID = 'classTest-mime';
|
||||
ob_end_flush();
|
||||
|
||||
@@ -23,10 +23,6 @@ define('USE_DATABASE', true);
|
||||
require 'config.php';
|
||||
// override ECHO ALL FALSE
|
||||
$ECHO_ALL = true;
|
||||
// set session name
|
||||
if (!defined('SET_SESSION_NAME')) {
|
||||
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
|
||||
}
|
||||
// define log file id
|
||||
$LOG_FILE_ID = 'classTest-form';
|
||||
ob_end_flush();
|
||||
|
||||
@@ -21,10 +21,6 @@ ob_start();
|
||||
define('USE_DATABASE', false);
|
||||
// sample config
|
||||
require 'config.php';
|
||||
// set session name
|
||||
if (!defined('SET_SESSION_NAME')) {
|
||||
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
|
||||
}
|
||||
// define log file id
|
||||
$LOG_FILE_ID = 'classTest-pass';
|
||||
ob_end_flush();
|
||||
|
||||
@@ -21,14 +21,12 @@ ob_start();
|
||||
define('USE_DATABASE', true);
|
||||
// sample config
|
||||
require 'config.php';
|
||||
// set session name
|
||||
if (!defined('SET_SESSION_NAME')) {
|
||||
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
|
||||
}
|
||||
// define log file id
|
||||
$LOG_FILE_ID = 'classTest';
|
||||
$SET_SESSION_NAME = EDIT_SESSION_NAME;
|
||||
|
||||
// init login & backend class
|
||||
$session = new CoreLibs\Create\Session($SET_SESSION_NAME);
|
||||
$log = new CoreLibs\Debug\Logging([
|
||||
'log_folder' => BASE . LOG,
|
||||
'file_id' => $LOG_FILE_ID,
|
||||
@@ -40,14 +38,14 @@ $log = new CoreLibs\Debug\Logging([
|
||||
'print_all' => $PRINT_ALL ?? false,
|
||||
]);
|
||||
$db = new CoreLibs\DB\IO(DB_CONFIG, $log);
|
||||
$login = new CoreLibs\ACL\Login($db, $log);
|
||||
$login = new CoreLibs\ACL\Login($db, $log, $session);
|
||||
$locale = \CoreLibs\Language\GetLocale::setLocale();
|
||||
$l10n = new \CoreLibs\Language\L10n(
|
||||
$locale['locale'],
|
||||
$locale['domain'],
|
||||
$locale['path'],
|
||||
);
|
||||
$backend = new CoreLibs\Admin\Backend($db, $log, $l10n, $locale);
|
||||
$backend = new CoreLibs\Admin\Backend($db, $log, $session, $l10n, $locale);
|
||||
$backend->db->dbInfo(true);
|
||||
ob_end_flush();
|
||||
|
||||
|
||||
@@ -21,10 +21,6 @@ ob_start();
|
||||
define('USE_DATABASE', false);
|
||||
// sample config
|
||||
require 'config.php';
|
||||
// set session name
|
||||
if (!defined('SET_SESSION_NAME')) {
|
||||
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
|
||||
}
|
||||
// define log file id
|
||||
$LOG_FILE_ID = 'classTest-phpv';
|
||||
ob_end_flush();
|
||||
|
||||
@@ -21,10 +21,6 @@ ob_start();
|
||||
define('USE_DATABASE', false);
|
||||
// sample config
|
||||
require 'config.php';
|
||||
// set session name
|
||||
if (!defined('SET_SESSION_NAME')) {
|
||||
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
|
||||
}
|
||||
// define log file id
|
||||
$LOG_FILE_ID = 'classTest-randomkey';
|
||||
ob_end_flush();
|
||||
|
||||
@@ -14,10 +14,6 @@ ob_start();
|
||||
define('USE_DATABASE', false);
|
||||
// sample config
|
||||
require 'config.php';
|
||||
// set session name
|
||||
if (!defined('SET_SESSION_NAME')) {
|
||||
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
|
||||
}
|
||||
// define log file id
|
||||
$LOG_FILE_ID = 'classTest-readEnvFile';
|
||||
ob_end_flush();
|
||||
|
||||
@@ -21,10 +21,6 @@ ob_start();
|
||||
define('USE_DATABASE', false);
|
||||
// sample config
|
||||
require 'config.php';
|
||||
// set session name
|
||||
if (!defined('SET_SESSION_NAME')) {
|
||||
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
|
||||
}
|
||||
// define log file id
|
||||
$LOG_FILE_ID = 'classTest-runningtime';
|
||||
ob_end_flush();
|
||||
|
||||
@@ -43,10 +43,6 @@ ob_start();
|
||||
define('USE_DATABASE', false);
|
||||
// sample config
|
||||
require 'config.php';
|
||||
// set session name
|
||||
// if (!defined('SET_SESSION_NAME')) {
|
||||
// define('SET_SESSION_NAME', EDIT_SESSION_NAME);
|
||||
// }
|
||||
// define log file id
|
||||
$LOG_FILE_ID = 'classTest-session';
|
||||
ob_end_flush();
|
||||
@@ -62,6 +58,7 @@ $log = new CoreLibs\Debug\Logging([
|
||||
'print_all' => $PRINT_ALL ?? false,
|
||||
]);
|
||||
use CoreLibs\Create\Session;
|
||||
$session = new Session();
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: SESSION';
|
||||
print "<!DOCTYPE html>";
|
||||
@@ -76,15 +73,15 @@ $value = 'bar';
|
||||
|
||||
foreach (['123', '123-123', '123abc'] as $_session_name) {
|
||||
print "[UNSET] Session Name valid for " . $_session_name . ": "
|
||||
. (Session::checkValidSessionName($_session_name) ? 'Valid' : 'Invalid') . "<br>";
|
||||
. ($session->checkValidSessionName($_session_name) ? 'Valid' : 'Invalid') . "<br>";
|
||||
}
|
||||
|
||||
echo "Global session name: " . ($GLOBALS['SET_SESSION_NAME'] ?? '-') . "<br>";
|
||||
|
||||
print "[UNSET] Current session id: " . Session::getSessionId() . "<br>";
|
||||
print "[UNSET] Current session name: " . Session::getSessionName() . "<br>";
|
||||
print "[UNSET] Current session active: " . (Session::checkActiveSession() ? 'Yes' : 'No') . "<br>";
|
||||
print "[UNSET] Current session status: " . getSessionStatusString(Session::getSessionStatus()) . "<br>";
|
||||
print "[UNSET] Current session id: " . $session->getSessionId() . "<br>";
|
||||
print "[UNSET] Current session name: " . $session->getSessionName() . "<br>";
|
||||
print "[UNSET] Current session active: " . ($session->checkActiveSession() ? 'Yes' : 'No') . "<br>";
|
||||
print "[UNSET] Current session status: " . getSessionStatusString($session->getSessionStatus()) . "<br>";
|
||||
if (isset($_SESSION)) {
|
||||
print "[UNSET] _SESSION is: set<br>";
|
||||
} else {
|
||||
@@ -92,22 +89,22 @@ if (isset($_SESSION)) {
|
||||
}
|
||||
#
|
||||
print "[UNSET] To set session name valid: "
|
||||
. (Session::checkValidSessionName($session_name) ? 'Valid' : 'Invalid') . "<br>";
|
||||
if (false === ($session = Session::startSession($session_name))) {
|
||||
print "[FAILED] Session start failed: " . Session::getErrorStr() . "<br>";
|
||||
. ($session->checkValidSessionName($session_name) ? 'Valid' : 'Invalid') . "<br>";
|
||||
if (false === ($session_id = $session->startSession($session_name))) {
|
||||
print "[FAILED] Session start failed: " . $session->getErrorStr() . "<br>";
|
||||
} else {
|
||||
print "[SET] Current session id: " . $session . "<br>";
|
||||
print "[SET] Current session id: " . $session_id . "<br>";
|
||||
}
|
||||
// set again
|
||||
if (false === ($session = Session::startSession($session_name))) {
|
||||
print "[2 FAILED] Session start failed: " . Session::getErrorStr() . "<br>";
|
||||
if (false === ($session_id = $session->startSession($session_name))) {
|
||||
print "[2 FAILED] Session start failed: " . $session->getErrorStr() . "<br>";
|
||||
} else {
|
||||
print "[2 SET] Current session id: " . $session . "<br>";
|
||||
print "[2 SET] Current session id: " . $session_id . "<br>";
|
||||
}
|
||||
print "[SET] Current session id: " . Session::getSessionId() . "<br>";
|
||||
print "[SET] Current session name: " . Session::getSessionName() . "<br>";
|
||||
print "[SET] Current session active: " . (Session::checkActiveSession() ? 'Yes' : 'No') . "<br>";
|
||||
print "[SET] Current session status: " . getSessionStatusString(Session::getSessionStatus()) . "<br>";
|
||||
print "[SET] Current session id: " . $session->getSessionId() . "<br>";
|
||||
print "[SET] Current session name: " . $session->getSessionName() . "<br>";
|
||||
print "[SET] Current session active: " . ($session->checkActiveSession() ? 'Yes' : 'No') . "<br>";
|
||||
print "[SET] Current session status: " . getSessionStatusString($session->getSessionStatus()) . "<br>";
|
||||
if (isset($_SESSION)) {
|
||||
print "[SET] _SESSION is: set<br>";
|
||||
} else {
|
||||
@@ -117,51 +114,51 @@ if (!isset($_SESSION['counter'])) {
|
||||
$_SESSION['counter'] = 0;
|
||||
}
|
||||
$_SESSION['counter']++;
|
||||
print "[READ] " . $var . ": " . ($_SESSION[$var] ?? '{UNSET}') . "<br>";
|
||||
print "[READ] A " . $var . ": " . ($_SESSION[$var] ?? '{UNSET}') . "<br>";
|
||||
$_SESSION[$var] = $value;
|
||||
print "[READ] " . $var . ": " . ($_SESSION[$var] ?? '{UNSET}') . "<br>";
|
||||
print "[READ] B " . $var . ": " . ($_SESSION[$var] ?? '{UNSET}') . "<br>";
|
||||
print "[READ] Confirm " . $var . " is " . $value . ": "
|
||||
. (($_SESSION[$var] ?? '') == $value ? 'Matching' : 'Not matching') . "<br>";
|
||||
|
||||
// differnt session name
|
||||
$session_name = 'class-test-session-ALT';
|
||||
if (false === ($session = Session::startSession($session_name))) {
|
||||
print "[3 FAILED] Session start failed: " . Session::getErrorStr() . "<br>";
|
||||
if (false === ($session_id = $session->startSession($session_name))) {
|
||||
print "[3 FAILED] Session start failed: " . $session->getErrorStr() . "<br>";
|
||||
} else {
|
||||
print "[3 SET] Current session id: " . $session . "<br>";
|
||||
print "[3 SET] Current session id: " . $session_id . "<br>";
|
||||
}
|
||||
print "[SET AGAIN] Current session id: " . Session::getSessionId() . "<br>";
|
||||
print "[SET AGAIN] Current session id: " . $session->getSessionId() . "<br>";
|
||||
|
||||
print "[ALL SESSION]: " . \CoreLibs\Debug\Support::printAr($_SESSION) . "<br>";
|
||||
|
||||
// close session
|
||||
Session::writeClose();
|
||||
$session->writeClose();
|
||||
// will never be written
|
||||
$_SESSION['will_never_be_written'] = 'empty';
|
||||
|
||||
// open again
|
||||
$session_name = 'class-test-session';
|
||||
if (false === ($session = Session::startSession($session_name))) {
|
||||
print "[4 FAILED] Session start failed: " . Session::getErrorStr() . "<br>";
|
||||
if (false === ($session_id = $session->startSession($session_name))) {
|
||||
print "[4 FAILED] Session start failed: " . $session->getErrorStr() . "<br>";
|
||||
} else {
|
||||
print "[4 SET] Current session id: " . $session . "<br>";
|
||||
print "[4 SET] Current session id: " . $session_id . "<br>";
|
||||
}
|
||||
print "[START AGAIN] Current session id: " . Session::getSessionId() . "<br>";
|
||||
print "[START AGAIN] Current session id: " . $session->getSessionId() . "<br>";
|
||||
$_SESSION['will_be_written_again'] = 'Full';
|
||||
|
||||
// close session
|
||||
Session::writeClose();
|
||||
$session->writeClose();
|
||||
// invalid
|
||||
$session_name = '123';
|
||||
if (false === ($session = Session::startSession($session_name))) {
|
||||
print "[5 FAILED] Session start failed: " . Session::getErrorStr() . "<br>";
|
||||
if (false === ($session_id = $session->startSession($session_name))) {
|
||||
print "[5 FAILED] Session start failed: " . $session->getErrorStr() . "<br>";
|
||||
} else {
|
||||
print "[5 SET] Current session id: " . $session . "<br>";
|
||||
print "[5 SET] Current session id: " . $session_id . "<br>";
|
||||
}
|
||||
print "[BAD NAME] Current session id: " . Session::getSessionId() . "<br>";
|
||||
print "[BAD NAME] Current session name: " . Session::getSessionName() . "<br>";
|
||||
print "[BAD NAME] Current session active: " . (Session::checkActiveSession() ? 'Yes' : 'No') . "<br>";
|
||||
print "[BAD NAME] Current session status: " . getSessionStatusString(Session::getSessionStatus()) . "<br>";
|
||||
print "[BAD NAME] Current session id: " . $session->getSessionId() . "<br>";
|
||||
print "[BAD NAME] Current session name: " . $session->getSessionName() . "<br>";
|
||||
print "[BAD NAME] Current session active: " . ($session->checkActiveSession() ? 'Yes' : 'No') . "<br>";
|
||||
print "[BAD NAME] Current session status: " . getSessionStatusString($session->getSessionStatus()) . "<br>";
|
||||
|
||||
// error message
|
||||
print $log->printErrorMsg();
|
||||
|
||||
@@ -43,10 +43,6 @@ ob_start();
|
||||
define('USE_DATABASE', false);
|
||||
// sample config
|
||||
require 'config.php';
|
||||
// set session name
|
||||
if (!defined('SET_SESSION_NAME')) {
|
||||
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
|
||||
}
|
||||
// define log file id
|
||||
$LOG_FILE_ID = 'classTest-session.read';
|
||||
ob_end_flush();
|
||||
@@ -62,6 +58,7 @@ $log = new CoreLibs\Debug\Logging([
|
||||
'print_all' => $PRINT_ALL ?? false,
|
||||
]);
|
||||
use CoreLibs\Create\Session;
|
||||
$session = new Session();
|
||||
|
||||
$PAGE_NAME = 'TEST CLASS: SESSION (READ)';
|
||||
print "<!DOCTYPE html>";
|
||||
@@ -77,28 +74,28 @@ $value = 'bar';
|
||||
|
||||
echo "Global session name: " . ($GLOBALS['SET_SESSION_NAME'] ?? '-') . "<br>";
|
||||
|
||||
print "[UNSET] Current session id: " . Session::getSessionId() . "<br>";
|
||||
print "[UNSET] Current session name: " . Session::getSessionName() . "<br>";
|
||||
print "[UNSET] Current session active: " . (Session::checkActiveSession() ? 'Yes' : 'No') . "<br>";
|
||||
print "[UNSET] Current session status: " . getSessionStatusString(Session::getSessionStatus()) . "<br>";
|
||||
print "[UNSET] Current session id: " . $session->getSessionId() . "<br>";
|
||||
print "[UNSET] Current session name: " . $session->getSessionName() . "<br>";
|
||||
print "[UNSET] Current session active: " . ($session->checkActiveSession() ? 'Yes' : 'No') . "<br>";
|
||||
print "[UNSET] Current session status: " . getSessionStatusString($session->getSessionStatus()) . "<br>";
|
||||
|
||||
print "[READ] " . $var . ": " . ($_SESSION[$var] ?? '{UNSET}') . "<br>";
|
||||
// start
|
||||
if (false === ($session = Session::startSession($session_name))) {
|
||||
print "Session start failed: " . Session::getErrorStr() . "<br>";
|
||||
if (false === ($session_id = $session->startSession($session_name))) {
|
||||
print "Session start failed: " . $session->getErrorStr() . "<br>";
|
||||
} else {
|
||||
print "Current session id: " . $session . "<br>";
|
||||
print "Current session id: " . $session_id . "<br>";
|
||||
}
|
||||
// set again
|
||||
if (false === ($session = Session::startSession($session_name))) {
|
||||
if (false === ($session_id = $session->startSession($session_name))) {
|
||||
print "[2] Session start failed<br>";
|
||||
} else {
|
||||
print "[2] Current session id: " . $session . "<br>";
|
||||
print "[2] Current session id: " . $session_id . "<br>";
|
||||
}
|
||||
print "[SET] Current session id: " . Session::getSessionId() . "<br>";
|
||||
print "[SET] Current session name: " . Session::getSessionName() . "<br>";
|
||||
print "[SET] Current session active: " . (Session::checkActiveSession() ? 'Yes' : 'No') . "<br>";
|
||||
print "[SET] Current session status: " . getSessionStatusString(Session::getSessionStatus()) . "<br>";
|
||||
print "[SET] Current session id: " . $session->getSessionId() . "<br>";
|
||||
print "[SET] Current session name: " . $session->getSessionName() . "<br>";
|
||||
print "[SET] Current session active: " . ($session->checkActiveSession() ? 'Yes' : 'No') . "<br>";
|
||||
print "[SET] Current session status: " . getSessionStatusString($session->getSessionStatus()) . "<br>";
|
||||
print "[READ] " . $var . ": " . ($_SESSION[$var] ?? '{UNSET}') . "<br>";
|
||||
print "[READ] Confirm " . $var . " is " . $value . ": "
|
||||
. (($_SESSION[$var] ?? '') == $value ? 'Matching' : 'Not matching') . "<br>";
|
||||
|
||||
@@ -23,10 +23,6 @@ define('USE_DATABASE', true);
|
||||
require 'config.php';
|
||||
// override ECHO ALL FALSE
|
||||
$ECHO_ALL = true;
|
||||
// set session name
|
||||
if (!defined('SET_SESSION_NAME')) {
|
||||
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
|
||||
}
|
||||
// define log file id
|
||||
$LOG_FILE_ID = 'classTest-smarty';
|
||||
ob_end_flush();
|
||||
|
||||
@@ -21,10 +21,6 @@ ob_start();
|
||||
define('USE_DATABASE', false);
|
||||
// sample config
|
||||
require 'config.php';
|
||||
// set session name
|
||||
if (!defined('SET_SESSION_NAME')) {
|
||||
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
|
||||
}
|
||||
// define log file id
|
||||
$LOG_FILE_ID = 'classTest-system';
|
||||
ob_end_flush();
|
||||
@@ -50,16 +46,23 @@ print "<body>";
|
||||
print '<div><a href="class_test.php">Class Test Master</a></div>';
|
||||
print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
||||
|
||||
print "System::getHostName():<br>";
|
||||
print "GETHOSTNAME: " . DgS::printAr(System::getHostName()) . "<br>";
|
||||
print "System::getPageName():<br>";
|
||||
print "GETPAGENAME(0): " . System::getPageName() . "<br>";
|
||||
print "GETPAGENAME(1): " . System::getPageName(System::NO_EXTENSION) . "<br>";
|
||||
print "GETPAGENAME(2): " . System::getPageName(System::FULL_PATH) . "<br>";
|
||||
print "System::getPageNameArray():<br>";
|
||||
print "GETPAGENAMEARRAY: " . \CoreLibs\Debug\Support::printAr(System::getPageNameArray()) . "<br>";
|
||||
// seting errro codes file upload
|
||||
print "System::fileUploadErrorMessage():<br>";
|
||||
print "FILEUPLOADERRORMESSAGE(): " . System::fileUploadErrorMessage(-1) . "<br>";
|
||||
print "FILEUPLOADERRORMESSAGE(UPLOAD_ERR_CANT_WRITE): "
|
||||
. System::fileUploadErrorMessage(UPLOAD_ERR_CANT_WRITE) . "<br>";
|
||||
|
||||
print "System::checkCLI():<br>";
|
||||
print "Are we in an CLI: " . (System::checkCLI() ? 'Yes' : 'No') . "<br>";
|
||||
|
||||
// error message
|
||||
print $log->printErrorMsg();
|
||||
|
||||
|
||||
@@ -21,10 +21,6 @@ ob_start();
|
||||
define('USE_DATABASE', false);
|
||||
// sample config
|
||||
require 'config.php';
|
||||
// set session name
|
||||
if (!defined('SET_SESSION_NAME')) {
|
||||
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
|
||||
}
|
||||
// define log file id
|
||||
$LOG_FILE_ID = 'classTest-token';
|
||||
ob_end_flush();
|
||||
|
||||
@@ -21,10 +21,6 @@ ob_start();
|
||||
define('USE_DATABASE', false);
|
||||
// sample config
|
||||
require 'config.php';
|
||||
// set session name
|
||||
if (!defined('SET_SESSION_NAME')) {
|
||||
define('SET_SESSION_NAME', EDIT_SESSION_NAME);
|
||||
}
|
||||
// define log file id
|
||||
$LOG_FILE_ID = 'classTest-uids';
|
||||
ob_end_flush();
|
||||
|
||||
@@ -150,8 +150,6 @@ define('SERVER_PATH_HASH', hash('crc32b', BASE));
|
||||
define('EDIT_SESSION_NAME', BASE_NAME . 'Admin' . SERVER_NAME_HASH . SERVER_PATH_HASH);
|
||||
// frontend
|
||||
define('SESSION_NAME', BASE_NAME . SERVER_NAME_HASH . SERVER_PATH_HASH);
|
||||
// SET_SESSION_NAME should be set in the header if a special session name is needed
|
||||
define('SET_SESSION_NAME', SESSION_NAME);
|
||||
|
||||
/************* CACHE/COMPILE IDS *************/
|
||||
define('CACHE_ID', 'CACHE_' . BASE_NAME . '_' . SERVER_NAME_HASH);
|
||||
|
||||
@@ -42,11 +42,11 @@ if (isset($_POST['action']) && $_POST['action'] != 'download_csv' && !$AJAX_PAGE
|
||||
if ($AJAX_PAGE && !$ZIP_STREAM) {
|
||||
header("Content-Type: application/json; charset=UTF-8");
|
||||
}
|
||||
// start session
|
||||
CoreLibs\Create\Session::startSession();
|
||||
//------------------------------ basic variable settings start
|
||||
|
||||
//------------------------------ class init start
|
||||
// start session
|
||||
$session = new \CoreLibs\Create\Session($SET_SESSION_NAME);
|
||||
// create logger
|
||||
$log = new CoreLibs\Debug\Logging([
|
||||
'log_folder' => BASE . LOG,
|
||||
@@ -71,7 +71,7 @@ if (
|
||||
// db config with logger
|
||||
$db = new CoreLibs\DB\IO(DB_CONFIG, $log);
|
||||
// login & page access check
|
||||
$login = new CoreLibs\ACL\Login($db, $log);
|
||||
$login = new CoreLibs\ACL\Login($db, $log, $session);
|
||||
// lang, path, domain
|
||||
// pre auto detect language after login
|
||||
$locale = \CoreLibs\Language\GetLocale::setLocale();
|
||||
@@ -84,7 +84,7 @@ $l10n = new \CoreLibs\Language\L10n(
|
||||
// create smarty object
|
||||
$smarty = new CoreLibs\Template\SmartyExtend($l10n, $locale);
|
||||
// create new Backend class with db and loger attached
|
||||
$cms = new CoreLibs\Admin\Backend($db, $log, $l10n, $locale);
|
||||
$cms = new CoreLibs\Admin\Backend($db, $log, $session, $l10n, $locale);
|
||||
// the menu show flag (what menu to show)
|
||||
$cms->menu_show_flag = 'main';
|
||||
// db info
|
||||
|
||||
@@ -33,8 +33,6 @@ extract($_POST, EXTR_SKIP);
|
||||
|
||||
ob_start();
|
||||
require 'config.php';
|
||||
// set session name here
|
||||
// $SET_SESSION_NAME = EDIT_SESSION_NAME;
|
||||
// overrride debug flags
|
||||
if (!DEBUG) {
|
||||
$DEBUG_ALL = false;
|
||||
@@ -45,8 +43,8 @@ if (!DEBUG) {
|
||||
|
||||
// should be utf8
|
||||
header("Content-type: text/html; charset=" . DEFAULT_ENCODING);
|
||||
// set session
|
||||
\CoreLibs\Create\Session::startSession(EDIT_SESSION_NAME);
|
||||
// start session
|
||||
$session = new \CoreLibs\Create\Session(EDIT_SESSION_NAME);
|
||||
// init logger
|
||||
$log = new CoreLibs\Debug\Logging([
|
||||
'log_folder' => BASE . LOG,
|
||||
@@ -60,7 +58,7 @@ $log = new CoreLibs\Debug\Logging([
|
||||
// db connection
|
||||
$db = new CoreLibs\DB\IO(DB_CONFIG, $log);
|
||||
// login page
|
||||
$login = new CoreLibs\ACL\Login($db, $log);
|
||||
$login = new CoreLibs\ACL\Login($db, $log, $session);
|
||||
// lang, path, domain
|
||||
// pre auto detect language after login
|
||||
$locale = \CoreLibs\Language\GetLocale::setLocale();
|
||||
|
||||
@@ -69,7 +69,6 @@ declare(strict_types=1);
|
||||
namespace CoreLibs\ACL;
|
||||
|
||||
use CoreLibs\Check\Password;
|
||||
use CoreLibs\Create\Session;
|
||||
|
||||
class Login
|
||||
{
|
||||
@@ -162,24 +161,30 @@ class Login
|
||||
public $db;
|
||||
/** @var \CoreLibs\Language\L10n language */
|
||||
public $l;
|
||||
/** @var \CoreLibs\Create\Session session class */
|
||||
public $session;
|
||||
|
||||
/**
|
||||
* constructor, does ALL, opens db, works through connection checks,
|
||||
* finishes itself
|
||||
*
|
||||
* @param \CoreLibs\DB\IO $db Database connection class
|
||||
* @param \CoreLibs\Debug\Logging $log Logging class
|
||||
* @param \CoreLibs\DB\IO $db Database connection class
|
||||
* @param \CoreLibs\Debug\Logging $log Logging class
|
||||
* @param \CoreLibs\Create\Session $session Session interface class
|
||||
*/
|
||||
public function __construct(
|
||||
\CoreLibs\DB\IO $db,
|
||||
\CoreLibs\Debug\Logging $log
|
||||
\CoreLibs\Debug\Logging $log,
|
||||
\CoreLibs\Create\Session $session
|
||||
) {
|
||||
// attach db class
|
||||
$this->db = $db;
|
||||
// log login data for this class only
|
||||
$log->setLogPer('class', true);
|
||||
// attach logger
|
||||
$this->log = $log;
|
||||
// attach db class
|
||||
$this->db = $db;
|
||||
// attach session class
|
||||
$this->session = $session;
|
||||
// set internal page name
|
||||
$this->page_name = \CoreLibs\Get\System::getPageName();
|
||||
// set db special errors
|
||||
@@ -192,12 +197,9 @@ class Login
|
||||
// initial the session if there is no session running already
|
||||
// check if session exists and could be created
|
||||
// TODO: move session creation and check to outside?
|
||||
if (Session::startSession() === false) {
|
||||
if ($this->session->checkActiveSession() === false) {
|
||||
$this->login_error = 1;
|
||||
echo '<b>Session not started or could not be started!</b><br>'
|
||||
. 'Use \'\CoreLibs\Create\Session::startSession();\'.<br>'
|
||||
. 'For less problems with other session, you can set a '
|
||||
. 'session name with \'\CoreLibs\Create\Session::startSession(\'name\');\'.<br>';
|
||||
echo '<b>No active session found</b>';
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -289,7 +291,7 @@ class Login
|
||||
// ** LANGUAGE SET AFTER LOGIN **
|
||||
// set the locale
|
||||
if (
|
||||
Session::getSessionId() !== false &&
|
||||
$this->session->checkActiveSession() === true &&
|
||||
!empty($_SESSION['DEFAULT_LANG'])
|
||||
) {
|
||||
$locale = $_SESSION['DEFAULT_LOCALE'] ?? '';
|
||||
@@ -1369,7 +1371,7 @@ EOM;
|
||||
$q .= "NULL, ";
|
||||
}
|
||||
}
|
||||
$q .= "'" . Session::getSessionId() . "', ";
|
||||
$q .= "'" . $this->session->getSessionId() . "', ";
|
||||
$q .= "'" . $this->db->dbEscapeString($this->action) . "', ";
|
||||
$q .= "'" . $this->db->dbEscapeString($this->username) . "', ";
|
||||
$q .= "NULL, ";
|
||||
|
||||
@@ -101,6 +101,8 @@ class Backend
|
||||
public $db;
|
||||
/** @var \CoreLibs\Language\L10n language */
|
||||
public $l;
|
||||
/** @var \CoreLibs\Create\Session session class */
|
||||
public $session;
|
||||
// smarty publics [end processing in smarty class]
|
||||
/** @var array<mixed> */
|
||||
public $DATA;
|
||||
@@ -114,23 +116,27 @@ class Backend
|
||||
// CONSTRUCTOR / DECONSTRUCTOR |====================================>
|
||||
/**
|
||||
* main class constructor
|
||||
* @param \CoreLibs\DB\IO $db Database connection class
|
||||
* @param \CoreLibs\Debug\Logging $log Logging class
|
||||
* @param \CoreLibs\Language\L10n $l10n l10n language class
|
||||
* @param array<string,string> $locale locale data read from setLocale
|
||||
* @param \CoreLibs\DB\IO $db Database connection class
|
||||
* @param \CoreLibs\Debug\Logging $log Logging class
|
||||
* @param \CoreLibs\Create\Session $session Session interface class
|
||||
* @param \CoreLibs\Language\L10n $l10n l10n language class
|
||||
* @param array<string,string> $locale locale data read from setLocale
|
||||
*/
|
||||
public function __construct(
|
||||
\CoreLibs\DB\IO $db,
|
||||
\CoreLibs\Debug\Logging $log,
|
||||
\CoreLibs\Create\Session $session,
|
||||
\CoreLibs\Language\L10n $l10n,
|
||||
array $locale
|
||||
) {
|
||||
// attach db class
|
||||
$this->db = $db;
|
||||
// set to log not per class
|
||||
$log->setLogPer('class', false);
|
||||
// attach logger
|
||||
$this->log = $log;
|
||||
// attach db class
|
||||
$this->db = $db;
|
||||
// attach session class
|
||||
$this->session = $session;
|
||||
// get the language sub class & init it
|
||||
$this->l = $l10n;
|
||||
// parse and read, legacy stuff
|
||||
@@ -232,9 +238,9 @@ class Backend
|
||||
. "'" . $this->db->dbEscapeString($_SERVER['HTTP_ACCEPT'] ?? '') . "', "
|
||||
. "'" . $this->db->dbEscapeString($_SERVER['HTTP_ACCEPT_CHARSET'] ?? '') . "', "
|
||||
. "'" . $this->db->dbEscapeString($_SERVER['HTTP_ACCEPT_ENCODING'] ?? '') . "', "
|
||||
. (\CoreLibs\Create\Session::getSessionId() === false ?
|
||||
. ($this->session->getSessionId() === false ?
|
||||
"NULL" :
|
||||
"'" . \CoreLibs\Create\Session::getSessionId() . "'")
|
||||
"'" . $this->session->getSessionId() . "'")
|
||||
. ", "
|
||||
. "'" . $this->db->dbEscapeString($this->action) . "', "
|
||||
. "'" . $this->db->dbEscapeString($this->action_id) . "', "
|
||||
|
||||
@@ -66,6 +66,8 @@ class Basic
|
||||
// logging interface, Debug\Logging class
|
||||
/** @var \CoreLibs\Debug\Logging */
|
||||
public $log;
|
||||
/** @var\CoreLibs\Create\Session */
|
||||
public $session;
|
||||
|
||||
// email valid checks
|
||||
/** @var array<mixed> */
|
||||
@@ -148,7 +150,7 @@ class Basic
|
||||
$this->email_regex_check = \CoreLibs\Check\Email::getEmailRegexCheck();
|
||||
|
||||
// initial the session if there is no session running already
|
||||
\CoreLibs\Create\Session::startSession($session_name);
|
||||
$this->session = new \CoreLibs\Create\Session($session_name ?? '');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* start a php sesseion
|
||||
* name can be given via startSession parameter
|
||||
* if not set tries to read $SET_SESSION_NAME from global
|
||||
* if this is not set tries to read SET_SESSION_NAME constant
|
||||
* else will use default set in php.ini
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
@@ -16,13 +16,29 @@ namespace CoreLibs\Create;
|
||||
class Session
|
||||
{
|
||||
/** @var string list for errors*/
|
||||
private static $error_str = '';
|
||||
private $error_str = '';
|
||||
|
||||
/**
|
||||
* init a session
|
||||
* init a session, if array is empty or array does not have session_name set
|
||||
* then no auto init is run
|
||||
*
|
||||
* @param string $session_name if set and not empty, will start session
|
||||
*/
|
||||
public function __construct()
|
||||
public function __construct(string $session_name = '')
|
||||
{
|
||||
if (!empty($session_name)) {
|
||||
$this->startSession($session_name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* check if we are in CLI, we set this, so we can mock this too
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function checkCLI(): bool
|
||||
{
|
||||
return \CoreLibs\Get\System::checkCLI();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -30,9 +46,9 @@ class Session
|
||||
*
|
||||
* @return string Last error string
|
||||
*/
|
||||
public static function getErrorStr(): string
|
||||
public function getErrorStr(): string
|
||||
{
|
||||
return self::$error_str;
|
||||
return $this->error_str;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,39 +85,30 @@ class Session
|
||||
* @param string|null $session_name
|
||||
* @return string|bool
|
||||
*/
|
||||
public static function startSession(?string $session_name = null)
|
||||
public function startSession(?string $session_name = null)
|
||||
{
|
||||
// we can't start sessions on command line
|
||||
if (\CoreLibs\Get\System::checkCLI()) {
|
||||
self::$error_str = '[SESSION] No sessions in php cli';
|
||||
if ($this->checkCLI()) {
|
||||
$this->error_str = '[SESSION] No sessions in php cli';
|
||||
return false;
|
||||
}
|
||||
// if session are OFF
|
||||
if (self::getSessionStatus() === PHP_SESSION_DISABLED) {
|
||||
self::$error_str = '[SESSION] Sessions are disabled';
|
||||
if ($this->getSessionStatus() === PHP_SESSION_DISABLED) {
|
||||
$this->error_str = '[SESSION] Sessions are disabled';
|
||||
return false;
|
||||
}
|
||||
// session_status
|
||||
// initial the session if there is no session running already
|
||||
if (!self::checkActiveSession()) {
|
||||
if (!$this->checkActiveSession()) {
|
||||
// if session name is emtpy, check if there is a global set
|
||||
// this is a deprecated fallback
|
||||
$session_name = $session_name ?? $GLOBALS['SET_SESSION_NAME'] ?? '';
|
||||
// check if we have an external session name given, else skip this step
|
||||
// this is a deprecated fallback
|
||||
if (
|
||||
empty($session_name) &&
|
||||
defined('SET_SESSION_NAME') &&
|
||||
!empty(SET_SESSION_NAME)
|
||||
) {
|
||||
// set the session name for possible later check
|
||||
$session_name = SET_SESSION_NAME;
|
||||
}
|
||||
// DEPRECTED: constant SET_SESSION_NAME is no longer used
|
||||
// if set, set special session name
|
||||
if (!empty($session_name)) {
|
||||
// invalid session name, abort
|
||||
if (!self::checkValidSessionName($session_name)) {
|
||||
self::$error_str = '[SESSION] Invalid session name: ' . $session_name;
|
||||
if (!$this->checkValidSessionName($session_name)) {
|
||||
$this->error_str = '[SESSION] Invalid session name: ' . $session_name;
|
||||
return false;
|
||||
}
|
||||
session_name($session_name);
|
||||
@@ -110,11 +117,11 @@ class Session
|
||||
session_start();
|
||||
}
|
||||
// if we still have no active session
|
||||
if (!self::checkActiveSession()) {
|
||||
self::$error_str = '[SESSION] Failed to activate session';
|
||||
if (!$this->checkActiveSession()) {
|
||||
$this->error_str = '[SESSION] Failed to activate session';
|
||||
return false;
|
||||
}
|
||||
return self::getSessionId();
|
||||
return $this->getSessionId();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -122,7 +129,7 @@ class Session
|
||||
*
|
||||
* @return string|bool
|
||||
*/
|
||||
public static function getSessionId()
|
||||
public function getSessionId()
|
||||
{
|
||||
return session_id();
|
||||
}
|
||||
@@ -132,7 +139,7 @@ class Session
|
||||
*
|
||||
* @return string|bool
|
||||
*/
|
||||
public static function getSessionName()
|
||||
public function getSessionName()
|
||||
{
|
||||
return session_name();
|
||||
}
|
||||
@@ -143,9 +150,9 @@ class Session
|
||||
*
|
||||
* @return bool True if there is an active session, else false
|
||||
*/
|
||||
public static function checkActiveSession(): bool
|
||||
public function checkActiveSession(): bool
|
||||
{
|
||||
if (self::getSessionStatus() === PHP_SESSION_ACTIVE) {
|
||||
if ($this->getSessionStatus() === PHP_SESSION_ACTIVE) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
@@ -160,7 +167,7 @@ class Session
|
||||
*
|
||||
* @return bool True und sucess, false on failure
|
||||
*/
|
||||
public static function writeClose(): bool
|
||||
public function writeClose(): bool
|
||||
{
|
||||
return session_write_close();
|
||||
}
|
||||
@@ -175,7 +182,7 @@ class Session
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function getSessionStatus(): int
|
||||
public function getSessionStatus(): int
|
||||
{
|
||||
return session_status();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user