35 lines
703 B
PHP
35 lines
703 B
PHP
<?php
|
|
// includes/common.php
|
|
ini_set('session.cookie_httponly', 1);
|
|
ini_set('session.use_only_cookies', 1);
|
|
ini_set('session.cookie_secure', isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on');
|
|
session_start();
|
|
|
|
require_once __DIR__ . '/../db/config.php';
|
|
|
|
function is_logged_in() {
|
|
return isset($_SESSION['user_id']);
|
|
}
|
|
|
|
function require_login() {
|
|
if (!is_logged_in()) {
|
|
header('Location: login.php');
|
|
exit;
|
|
}
|
|
}
|
|
|
|
function require_guest() {
|
|
if (is_logged_in()) {
|
|
header('Location: index.php');
|
|
exit;
|
|
}
|
|
}
|
|
|
|
function get_user_id() {
|
|
return $_SESSION['user_id'] ?? null;
|
|
}
|
|
|
|
function get_user_name() {
|
|
return $_SESSION['username'] ?? null;
|
|
}
|
|
?>
|