<?php
declare(strict_types=1);
/**
* Session Helper
*
* app/Helpers/session_helper.php
*/
/**
* Clears the session data but keeps the session active.
*/
if (! function_exists('clearSession'))
{
/**
* clearSession ()
* -------------------------------------------------------------------
*
*/
function clearSession(): void
{
// Destroy the session data - but ensure a session is still
// available for flash messages, etc.
if (isset($_SESSION)) {
foreach ($_SESSION as $key => $value) {
$_SESSION[$key] = null;
unset($_SESSION[$key]);
}
}
// Regenerate the session ID for a touch of added safety.
session()->regenerate(true);
}
}
/**
* clearSessionFiles ()
* -----------------------------------------------------------------------
*/
if (! function_exists('clearSessionFiles'))
{
/**
* clearSessionFiles ()
* -------------------------------------------------------------------
*
*/
function clearSessionFiles(): void
{
// Counter for number of session files - dir . & .. and index.html
$count = 0;
// Get all files in our session folder
$listFile = scandir("../writable/session/");
foreach ($listFile as $file) {
// if the file is a . or .. directory skip it!
if (! is_dir("../writable/session/" . $file)) {
$count++;
}
// We now have all session files and will exclude the index.html file
if (! is_dir("../writable/session/" . $file)) {
if ($file !== "index.html") {
// unlink and delete the files
unlink("../writable/session/" . $file);
}
}
}
// Close the session, it will re-intialize itself.
session()->close();
// Log message
log_message('debug', "clearSessionFiles() - Deleted " . $count . " Session files");
}
}
/**
* clearLogFiles ()
* -----------------------------------------------------------------------
*/
if (! function_exists('clearLogFiles'))
{
/**
* clearLogFiles ()
* -------------------------------------------------------------------
*
*/
function clearLogFiles(): void
{
// Counter for number of log files - dir . & .. and index.html
$count = 0;
// Get all files in our logs folder
$listFile = scandir("../writable/logs/");
foreach ($listFile as $file) {
// if the file is a . or .. directory skip it!
if (! is_dir("../writable/logs/" . $file)) {
$count++;
}
// We now have all log files and will exclude the index.html file
if (! is_dir("../writable/logs/" . $file)) {
if ($file !== "index.html") {
// unlink and delete the log files
unlink("../writable/logs/" . $file);
}
}
}
// Log message
log_message('debug', "clearLogFiles() - Deleted " . $count . " Log files");
}
}
/**
* -----------------------------------------------------------------------
* Filename: session_helper.php
* Location: ./app/Helpers/session_helper.php
* -----------------------------------------------------------------------
*/