diff options
author | lonkaars <loek@pipeframe.xyz> | 2023-05-08 17:08:54 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2023-05-08 17:08:54 +0200 |
commit | cda96d31939c7ea727c114b162f43bb4d18314a2 (patch) | |
tree | aa1aac2c746c5a1452b11af3f187d499b5a9ce5f /lib/login.php | |
parent | 08d6281d872a8d2a496462f131cbdc860432acc0 (diff) |
more website
Diffstat (limited to 'lib/login.php')
-rw-r--r-- | lib/login.php | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/login.php b/lib/login.php new file mode 100644 index 0000000..1da5a02 --- /dev/null +++ b/lib/login.php @@ -0,0 +1,36 @@ +<?php +function check_login() { + if(!isset($_COOKIE['username'])) return false; + if(!isset($_COOKIE['password'])) return false; + + return true; +} + +$logged_in = check_login(); + +function if_logged_in($is, $redirect, $back = false) { + global $logged_in; + if ($logged_in != $is) return; + if ($back) { + $prev = $_SERVER['HTTP_REFERER']; + $ONE_HOUR = time() + (60 * 60); + setcookie("prev", $prev, $ONE_HOUR, "/"); + } + http_response_code(302); + header("Location: ".$redirect); + die(); +} + +function cookie_redir($username, $password, $url = "") { + $ONE_YEAR = time() + (60 * 60 * 24 * 365); + setcookie("username", $username, $ONE_YEAR, "/"); + setcookie("password", $password, $ONE_YEAR, "/"); // TODO: use tokens to login + if (!$url) { + $prev = $_COOKIE['prev']; + if(!$prev) $url = "/"; + else $url = $prev; + } + header("Location: ".$url); + die(); +} +?> |