summaryrefslogtreecommitdiff
path: root/src/accounts.php
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2025-04-20 16:06:19 +0500
committerilotterytea <iltsu@alright.party>2025-04-20 16:06:19 +0500
commit5fc857449011f76ed7677aad40576790310d23e1 (patch)
treea8bbff085c1cd83d5070c1bf4c013e79cfe8f938 /src/accounts.php
parent10cde47798f2a7b10a84a22f53aeddab1ceea720 (diff)
feat: moved from SQLite to MySQL
Diffstat (limited to 'src/accounts.php')
-rw-r--r--src/accounts.php15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/accounts.php b/src/accounts.php
index 4273964..330ad3c 100644
--- a/src/accounts.php
+++ b/src/accounts.php
@@ -1,4 +1,6 @@
<?php
+include_once "config.php";
+
function authorize_user()
{
session_start();
@@ -11,13 +13,14 @@ function authorize_user()
return;
}
- $db = new SQLite3("../../database.db");
+ include_once "config.php";
+
+ $db = new PDO(DB_URL, DB_USER, DB_PASS);
- $stmt = $db->prepare("SELECT id, username FROM users WHERE secret_key = :secret_key");
- $stmt->bindValue("secret_key", $_COOKIE["secret_key"]);
- $results = $stmt->execute();
+ $stmt = $db->prepare("SELECT id, username FROM users WHERE secret_key = ?");
+ $stmt->execute([$_COOKIE["secret_key"]]);
- if ($row = $results->fetchArray()) {
+ if ($row = $stmt->fetch()) {
$_SESSION["user_id"] = $row["id"];
$_SESSION["user_name"] = $row["username"];
} else {
@@ -25,5 +28,5 @@ function authorize_user()
setcookie("secret_key", "", time() - 1000);
}
- $db->close();
+ $db = null;
} \ No newline at end of file