summaryrefslogtreecommitdiff
path: root/public/account/signout.php
blob: dd1d0f98b54d83033e9c9d509ac86f16b0df03b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?php
include "../../src/utils.php";

session_start();

if (!isset($_SESSION["user_id"])) {
    header("Location: /account");
    exit;
}

$db = new SQLite3("../../database.db");

$stmt = $db->prepare("UPDATE users SET secret_key = :secret_key WHERE id = :id");
$stmt->bindValue(":id", $_SESSION["user_id"]);
$stmt->bindValue(":secret_key", generate_random_string(32));
$stmt->execute();

session_unset();
session_destroy();

setcookie("secret_key", "", time() - 1000);

$db->close();

header("Location: /account");