Try: ca/tecreations/ViewFile.php
<?php
GLOBAL $debug_sessions;
$debug_sessions = false;
require_once "FunctionsPHP.php";
class MySQLSessionHandler implements SessionHandlerInterface {
public $trace = false;
public $sessions_db;
function __construct() {
GLOBAL $DB_HOST, $DB_USER, $DB_PASS, $DB_NAME, $debug_sessions;
$this->db = new MySQL($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);
$this->db->setDebug($debug_sessions);
$this->trace = $debug_sessions;
}
function close() :bool {
if ($this->trace) print("<br />MySQLSessionHandler.close");
return true;
}
function destroy($sess_id) : bool {
if ($this->trace) print("<br />MySQLSessionHandler.destroy");
$this->db->issue("DELETE FROM SPRING_SESSION WHERE SESSION_ID = '" . session_id() . "';");
return true;
}
function gc($sess_maxlifetime) : bool {
if ($this->trace) print("<br />MySQLSessionHandler.gc");
$this->db->issue("DELETE FROM SPRING_SESSION WHERE LAST_ACCESS_TIME + $sess_maxlifetime < ".time().";");
die("<span style='color:red'>MySQLSessionHandler: GC'd Sessions</span>");
return true;
}
function open($save_path,$session_name) : bool {
if ($this->trace) print("<br />MySQLSessionHandler.open");
return true;
}
function read($id) : String {
GLOBAL $debug_sessions;
if ($this->trace) print("<br />MySQLSessionHandler.read");
$result = $this->db->select("SELECT PHP_DATA FROM SPRING_SESSION WHERE SESSION_ID = '" . session_id() . "';");
if ($debug_sessions) {
print("<br />MySQLSessionHandler.read: Result: ");
print_r($result);
print("<br />");
}
if ($result['count'] == 0) return "";
if ($result['count'] == 1) {
return $result['rows']['PHP_DATA'];
}
}
function setDebug($state = true) {
$this->db->setDebug($state);
$this->trace = $state;
}
public function write($id,$data): bool {
$primary_id = getRandomHexLower(8) . "-" . getRandomHexLower(4) . "-" . getRandomHexLower(4) .
"-" . getRandomHexLower(4) . "-" . getRandomHexLower(12);
if ($this->trace) print("<br />MySQLSessionHandler.write");
$this->db->issue("DELETE FROM SPRING_SESSION WHERE SESSION_ID='".session_id()."'");
$sql = "REPLACE INTO SPRING_SESSION (PRIMARY_ID,SESSION_ID, PHP_DATA, LAST_ACCESS_TIME, CREATION_TIME, MAX_INACTIVE_INTERVAL, EXPIRY_TIME) ";
$sql .= "VALUES('$primary_id','$id','$data','" . (time()*1000) . "','" . (time()*1000) . "','" . 1800 . "','" . ((time()*1000) + 1800000) . "');";
$this->db->issue($sql);
return true;
}
}