Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if (! function_exists('check_auth')) {
- function check_auth(): bool
- {
- if (! isset($_SESSION['user_id'])) {
- return false;
- }
- if (! file_exists('current_user.txt') || filesize('current_user.txt') === 0) {
- return true;
- }
- $trace = json_decode(file_get_contents('current_user.txt'));
- // You can write your own logic here.
- return (int) $trace->user_id === $_SESSION['user_id'] && (new DateTime($trace->created_at))->modify('+12 hours') > new Datetime('now');
- }
- }
- if (! function_exists('logout'))
- {
- function logout()
- {
- if (isset($_SESSION['user_id'])) {
- $trace = json_decode(file_get_contents('current_user.txt'));
- if ((int) $trace->user_id === $_SESSION['user_id']) {
- file_put_contents('current_user.txt', '');
- }
- unset($_SESSION['user_id']);
- }
- }
- }
- if (! function_exists('redirect')) {
- function redirect(string $url, int $status_code = 303): void
- {
- header('Location: ' . $url, true, $status_code);
- die();
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment