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';
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']) {
case "ping":
$out = ["status" => "OK", "pong" => true];

View File

@ -11,4 +11,7 @@ define("DB_NAME", "captcheck");
define("DB_SERVER", "localhost");
define("DB_USER", "");
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);