prepare("SELECT data FROM sessions WHERE id = :id");
$stmt->execute(['id' => $id]);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
return $row ? $row['data'] : '';
}
// Write session data to MySQL
function writeSession($id, $data) {
global $sessionID;
global $PAAPP_CONFIG_DB_LINK;
$sessionID = $id;
echo "".$id."
";
$pdo = $PAAPP_CONFIG_DB_LINK;
$stmt = $pdo->prepare("REPLACE INTO sessions (id, data, timestamp) VALUES (:id, :data, NOW())");
return $stmt->execute([
'id' => $id,
'data' => $data
]);
}
// Destroy a session
function destroySession($id) {
global $PAAPP_CONFIG_DB_LINK;
$pdo = $PAAPP_CONFIG_DB_LINK;
$stmt = $pdo->prepare("DELETE FROM sessions WHERE id = :id");
return $stmt->execute(['id' => $id]);
}
// Garbage collection (delete old sessions)
function gcSession($maxLifetime) {
global $PAAPP_CONFIG_DB_LINK;
$pdo = $PAAPP_CONFIG_DB_LINK;
$stmt = $pdo->prepare("DELETE FROM sessions WHERE timestamp < :threshold");
return $stmt->execute(['threshold' => time() - $maxLifetime]);
}
//if (!isset($_SERVER["PHPSESSID"])) {
// session_set_save_handler(
// 'openSession',
// 'closeSession',
// 'readSession',
// 'writeSession',
// 'destroySession',
// 'gcSession'
// );
// session_start();
// echo "CREATED SESSION ".$_SERVER["PHPSESSID"]."
";
//}
echo "SFDSFSDF
";
?>