Edit auth.php via Editor
This commit is contained in:
parent
fa1ebff600
commit
bda7319921
28
auth.php
28
auth.php
@ -1,11 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
// Start session if not already started
|
require_once __DIR__ . '/session_config.php';
|
||||||
if (session_status() === PHP_SESSION_NONE) {
|
|
||||||
session_start();
|
|
||||||
}
|
|
||||||
|
|
||||||
function check_auth() {
|
function check_auth() {
|
||||||
if (!isset($_SESSION['role']) || !isset($_SESSION['user_id'])) {
|
// Check if user is logged in
|
||||||
|
if (!isset($_SESSION['logged_in']) || !$_SESSION['logged_in'] || !isset($_SESSION['role']) || !isset($_SESSION['user_id'])) {
|
||||||
|
// Store the current page to redirect after login
|
||||||
|
$_SESSION['redirect_after_login'] = $_SERVER['REQUEST_URI'];
|
||||||
header('Location: login.php');
|
header('Location: login.php');
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
@ -25,5 +25,21 @@ function get_user_name() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function is_logged_in() {
|
function is_logged_in() {
|
||||||
return isset($_SESSION['role']) && isset($_SESSION['user_id']);
|
return isset($_SESSION['logged_in']) && $_SESSION['logged_in'] === true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function logout() {
|
||||||
|
$_SESSION = array();
|
||||||
|
|
||||||
|
if (ini_get("session.use_cookies")) {
|
||||||
|
$params = session_get_cookie_params();
|
||||||
|
setcookie(session_name(), '', time() - 42000,
|
||||||
|
$params["path"], $params["domain"],
|
||||||
|
$params["secure"], $params["httponly"]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
session_destroy();
|
||||||
|
header('Location: login.php');
|
||||||
|
exit();
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user