diff options
Diffstat (limited to 'src/accounts.php')
| -rw-r--r-- | src/accounts.php | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/accounts.php b/src/accounts.php new file mode 100644 index 0000000..4273964 --- /dev/null +++ b/src/accounts.php @@ -0,0 +1,29 @@ +<?php +function authorize_user() +{ + session_start(); + + if (!isset($_COOKIE["secret_key"])) { + if (isset($_SESSION["user_id"])) { + session_unset(); + } + + return; + } + + $db = new SQLite3("../../database.db"); + + $stmt = $db->prepare("SELECT id, username FROM users WHERE secret_key = :secret_key"); + $stmt->bindValue("secret_key", $_COOKIE["secret_key"]); + $results = $stmt->execute(); + + if ($row = $results->fetchArray()) { + $_SESSION["user_id"] = $row["id"]; + $_SESSION["user_name"] = $row["username"]; + } else { + session_regenerate_id(); + setcookie("secret_key", "", time() - 1000); + } + + $db->close(); +}
\ No newline at end of file |
