Browse Source

Automatically delete old sessions

tags/v0.1
Skylar Ittner 2 years ago
parent
commit
950650fd1f
2 changed files with 11 additions and 1 deletions
  1. 7
    0
      api.php
  2. 4
    1
      settings.template.php

+ 7
- 0
api.php 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];

+ 4
- 1
settings.template.php 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);

Loading…
Cancel
Save