BASE . LOG,
'file_id' => $LOG_FILE_ID,
// add file date
'print_file_date' => true,
// set debug and print flags
'debug_all' => $DEBUG_ALL ?? false,
'echo_all' => $ECHO_ALL ?? false,
'print_all' => $PRINT_ALL ?? false,
]);
use CoreLibs\Create\Session;
$PAGE_NAME = 'TEST CLASS: SESSION';
print "";
print "
" . $PAGE_NAME . "";
print "";
print '';
print '' . $PAGE_NAME . '
';
$session_name = 'class-test-session';
$var = 'foo';
$value = 'bar';
foreach (['123', '123-123', '123abc'] as $_session_name) {
print "[UNSET] Session Name valid for " . $_session_name . ": "
. (Session::checkValidSessionName($_session_name) ? 'Valid' : 'Invalid') . "
";
}
echo "Global session name: " . ($GLOBALS['SET_SESSION_NAME'] ?? '-') . "
";
print "[UNSET] Current session id: " . Session::getSessionId() . "
";
print "[UNSET] Current session name: " . Session::getSessionName() . "
";
print "[UNSET] Current session active: " . (Session::checkActiveSession() ? 'Yes' : 'No') . "
";
print "[UNSET] Current session status: " . getSessionStatusString(Session::getSessionStatus()) . "
";
if (isset($_SESSION)) {
print "[UNSET] _SESSION is: set
";
} else {
print "[UNSET] _SESSION is: not set
";
}
#
print "[UNSET] To set session name valid: "
. (Session::checkValidSessionName($session_name) ? 'Valid' : 'Invalid') . "
";
if (false === ($session = Session::startSession($session_name))) {
print "[FAILED] Session start failed: " . Session::getErrorStr() . "
";
} else {
print "[SET] Current session id: " . $session . "
";
}
// set again
if (false === ($session = Session::startSession($session_name))) {
print "[2 FAILED] Session start failed: " . Session::getErrorStr() . "
";
} else {
print "[2 SET] Current session id: " . $session . "
";
}
print "[SET] Current session id: " . Session::getSessionId() . "
";
print "[SET] Current session name: " . Session::getSessionName() . "
";
print "[SET] Current session active: " . (Session::checkActiveSession() ? 'Yes' : 'No') . "
";
print "[SET] Current session status: " . getSessionStatusString(Session::getSessionStatus()) . "
";
if (isset($_SESSION)) {
print "[SET] _SESSION is: set
";
} else {
print "[SET] _SESSION is: not set
";
}
if (!isset($_SESSION['counter'])) {
$_SESSION['counter'] = 0;
}
$_SESSION['counter']++;
print "[READ] " . $var . ": " . ($_SESSION[$var] ?? '{UNSET}') . "
";
$_SESSION[$var] = $value;
print "[READ] " . $var . ": " . ($_SESSION[$var] ?? '{UNSET}') . "
";
print "[READ] Confirm " . $var . " is " . $value . ": "
. (($_SESSION[$var] ?? '') == $value ? 'Matching' : 'Not matching') . "
";
// differnt session name
$session_name = 'class-test-session-ALT';
if (false === ($session = Session::startSession($session_name))) {
print "[3 FAILED] Session start failed: " . Session::getErrorStr() . "
";
} else {
print "[3 SET] Current session id: " . $session . "
";
}
print "[SET AGAIN] Current session id: " . Session::getSessionId() . "
";
print "[ALL SESSION]: " . \CoreLibs\Debug\Support::printAr($_SESSION) . "
";
// close session
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() . "
";
} else {
print "[4 SET] Current session id: " . $session . "
";
}
print "[START AGAIN] Current session id: " . Session::getSessionId() . "
";
$_SESSION['will_be_written_again'] = 'Full';
// close session
Session::writeClose();
// invalid
$session_name = '123';
if (false === ($session = Session::startSession($session_name))) {
print "[5 FAILED] Session start failed: " . Session::getErrorStr() . "
";
} else {
print "[5 SET] Current session id: " . $session . "
";
}
print "[BAD NAME] Current session id: " . Session::getSessionId() . "
";
print "[BAD NAME] Current session name: " . Session::getSessionName() . "
";
print "[BAD NAME] Current session active: " . (Session::checkActiveSession() ? 'Yes' : 'No') . "
";
print "[BAD NAME] Current session status: " . getSessionStatusString(Session::getSessionStatus()) . "
";
// error message
print $log->printErrorMsg();
print "";
// __END__