27 lines
No EOL
702 B
PHP
27 lines
No EOL
702 B
PHP
<?php
|
|
require("../libs/test_secret.php");
|
|
|
|
function auth($token) {
|
|
if (is_null($token)) return '!guest';
|
|
|
|
global $db;
|
|
|
|
$stmt = $db->prepare("SELECT * FROM token WHERE token = ?");
|
|
$stmt->execute([$token]);
|
|
|
|
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
if (!$result) return '!guest';
|
|
|
|
$username = $result['username'];
|
|
|
|
$stmt = $db->prepare("SELECT * FROM auth WHERE username = ?");
|
|
$stmt->execute([$username]);
|
|
|
|
$result = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
if (!$result) return '!guest';
|
|
|
|
return $username;
|
|
}
|
|
|
|
$username = auth($_COOKIE['token']);
|
|
?>
|