Automatically delete old sessions

This commit is contained in:
Skylar Ittner 2017-06-09 03:44:55 -06:00
parent 563399081b
commit 950650fd1f
2 changed files with 11 additions and 1 deletions

View File

@ -3,6 +3,13 @@
require __DIR__ . '/required.php'; require __DIR__ . '/required.php';
header("Content-Type: application/json"); header("Content-Type: application/json");
// Oldest session allowed
$session_min_date = date("Y-m-d H:i:s", strtotime("-" . SESSION_EXPIRE_MINUTES . " minutes"));
// Delete old sessions
$old_sessions = $database->select("sessions", "sid", ["timestamp[<]" => $session_min_date]);
$database->delete("scrambled_answers", ["sid" => $old_sessions]);
$database->delete("sessions", ["sid" => $old_sessions]);
switch ($VARS['action']) { switch ($VARS['action']) {
case "ping": case "ping":
$out = ["status" => "OK", "pong" => true]; $out = ["status" => "OK", "pong" => true];

View File

@ -12,3 +12,6 @@ define("DB_SERVER", "localhost");
define("DB_USER", ""); define("DB_USER", "");
define("DB_PASS", ""); define("DB_PASS", "");
define("DB_CHARSET", "utf8"); define("DB_CHARSET", "utf8");
// Sessions more than this many minutes old will be automatically deleted.
define("SESSION_EXPIRE_MINUTES", 30);