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