e949/api/_auth.php

30 lines
678 B
PHP
Raw Normal View History

2023-08-12 04:09:17 +05:30
<?php
require_once("_db.php"); //("api/_db.php");
// Check if request was to specified file
function ThisFileIsRequested ($fullpath) {
return substr($fullpath, -strlen($_SERVER["SCRIPT_NAME"])) === $_SERVER["SCRIPT_NAME"];
}
2023-08-12 04:09:17 +05:30
session_start();
$LOGGED_IN = false;
if (isset($_SESSION["userid"])) {
// Check if user still exist
$s = $db->prepare("SELECT * FROM users WHERE id = ?");
$s->bind_param("s", $_SESSION["userid"]);
$s->execute();
if (!(bool)$s->get_result()->fetch_assoc()) { // If not, then destroy session
2023-08-12 04:09:17 +05:30
session_unset();
session_destroy();
echo "user id does not exist";
die("user id used in session does not exist");
}
$LOGGED_IN = true;
}
?>