Try: ca/tecreations/ViewFile.php -- Online
<?php
require_once "FunctionsPHP.php";
class MySQLSessionHandler implements SessionHandlerInterface {
var $trace = true;
var $debug = true;
function __construct() {
GLOBAL $DB_HOST, $DB_USER, $DB_PASS, $DB_NAME;
$this->db = new MySQL($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);
}
function close() :bool {
if ($this->trace) $this->trace("MySQLSessionHandler.close");
return true;
}
function createTable() {
$sql = "CREATE TABLE PHP_SESSION (" .
"PRIMARY_ID bigint AUTO_INCREMENT PRIMARY KEY," .
"SESSION_ID varchar (256) NOT NULL," .
"DATA varchar (8192) NOT NULL DEFAULT ''," .
"LAST_ACCESS varchar (128) NOT NULL," .
"MAX_INACTIVE_INTERVAL INT(5) NOT NULL DEFAULT '3600'" .
")";
if ($this->debug) $this->debug($sql);
$this->db->issue($sql);
}
function destroy($id) : bool {
if ($this->trace) $this->trace("MySQLSessionHandler.destroy");
$this->db->issue("DELETE FROM PHP_SESSION WHERE SESSION_ID = '$id'");
return true;
}
function gc($sess_maxlifetime) : bool {
global $IS_WEB;
if ($this->trace) $this->trace("MySQLSessionHandler.gc");
if ($this->debug) {
if ($IS_WEB) {
$this->debug("<span style='color:red'>MySQLSessionHandler: GC'd Sessions</span>");
} else {
$this->debug("MySQLSessionHandler: GC'd Sessions");
}
}
return true;
}
function open($save_path,$session_name) : bool {
if ($this->trace) print("<br />MySQLSessionHandler.open");
return true;
}
function debug($msg = "") {
global $IS_WEB;
if ($msg == "") die("Calls to debug(\$msg) must not be empty.");
if ($IS_WEB) {
print("<br />$msg<br />");
} else {
print("$msg\n");
}
}
function print($msg = "", $array = "") {
global $IS_WEB;
if (!($msg == "")) {
if ($IS_WEB) {
print("<br />$msg: ");
if (is_array($array)) print_r($array);
} else {
print($msg . ": \n");
if (is_array($array)) print_r($array);
}
}
}
function trace($id = "") {
global $IS_WEB;
if ($id == "") die("Calls to trace() must identify themselves.");
if ($IS_WEB) {
print("<br />$id<br />");
} else {
print("$id\n");
}
}
function read($id) : String {
global $IS_WEB;
if ($this->trace) $this->trace("MySQLSessionHandler.read");
$result = $this->db->select("SELECT DATA FROM PHP_SESSION WHERE SESSION_ID='$id'");
if ($this->debug) {
$this->print("read: Result",$result);
}
if ($result['count'] == 0) return "";
if ($result['count'] == 1) {
return $result['rows']['DATA'];
}
}
function resetTable() {
$this->db->issue("DROP TABLE IF EXISTS PHP_SESSION");
$this->createTable();
}
function setDBDebug($state = true) {
$this->db->setDebug($state);
}
function setDebug($state = true) {
$this->debug = $state;
}
function setTrace($state = true) {
$this->trace = $state;
}
public function write($id,$data): bool {
global $IS_WEB, $time;
if ($this->trace) $this->trace("MySQLSessionHandler.write");
$this->db->issue("DELETE FROM PHP_SESSION WHERE SESSION_ID='$id'");
$sql = "INSERT INTO PHP_SESSION (SESSION_ID,DATA, LAST_ACCESS) ";
$sql .= "VALUES('$id','$data','" . mysqli_real_escape_string($this->db->getMYSQLI(),$time->getTimsTime()) . "')";
if ($this->debug) {
print("write: SQL: $sql");
}
$this->db->issue($sql);
return true;
}
}