mirror of
https://github.com/tim-krehan/shopping-list.git
synced 2024-11-30 16:40:36 +01:00
27 lines
814 B
PHP
27 lines
814 B
PHP
<?php
|
|
include $_SESSION["docroot"].'/config/config.php';
|
|
include $_SESSION["docroot"].'/php/connect.php';
|
|
if(!(preg_match("/error.+/", $_SERVER["REQUEST_URI"])))
|
|
{
|
|
# clear expired sessions from the database
|
|
$mysqli->query('DELETE FROM `sessions` WHERE `expires` < NOW();');
|
|
|
|
if(isset($_COOKIE["token"])){
|
|
$token = $_COOKIE["token"];
|
|
}
|
|
else{
|
|
$token = "-1";
|
|
}
|
|
|
|
$selectQuery = $mysqli->prepare('SELECT * FROM `sessions` WHERE `session_id` = ?;');
|
|
$selectQuery->bind_param("s", $token);
|
|
$selectQuery->execute();
|
|
$result = $selectQuery->get_result();
|
|
|
|
if(($result->num_rows) == 0 && (!(in_array("site", array_keys($_GET))) || $_GET["site"]!="login"))
|
|
{
|
|
header('Location: /login/url='.$_SERVER["REQUEST_URI"]);
|
|
}
|
|
$mysqli->close();
|
|
}
|
|
?>
|