summaryrefslogtreecommitdiff
path: root/public/account/delete.php
blob: 99aebe5d6aded93c5e5fef6742e4575f2350fe72 (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
26
27
28
29
30
31
32
33
34
35
36
<?php
include "../../src/utils.php";
include_once "../../src/config.php";

session_start();

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

$id = $_SESSION["user_id"];

$db = new PDO(DB_URL, DB_USER, DB_PASS);
$db->prepare("DELETE FROM users WHERE id = ?")->execute([$id]);

session_unset();
session_destroy();

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

$db = null;

$path = "../static/userdata/avatars/$id";
if (is_dir($path)) {
    array_map("unlink", glob("$path/*.*"));
    rmdir($path);
}

$path = "../static/userdata/banners/$id";
if (is_dir($path)) {
    array_map("unlink", glob("$path/*.*"));
    rmdir($path);
}

header("Location: /account");