-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathfixed.php
More file actions
28 lines (22 loc) · 690 Bytes
/
Copy pathfixed.php
File metadata and controls
28 lines (22 loc) · 690 Bytes
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
<?php
declare(strict_types=1);
require __DIR__ . '/../../src/db.php';
require __DIR__ . '/../../src/csrf.php';
session_start();
$_SESSION['user'] ??= 'demo-user';
$pdo = db();
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
csrf_verify($_POST['_token'] ?? '');
$stmt = $pdo->prepare('DELETE FROM users WHERE name = :name');
$stmt->execute(['name' => $_SESSION['user']]);
echo "Deleted account for {$_SESSION['user']}";
exit;
}
$token = csrf_token();
?>
<!doctype html>
<title>CSRF (fixed)</title>
<form method="post">
<input type="hidden" name="_token" value="<?= htmlspecialchars($token, ENT_QUOTES) ?>">
<button type="submit">Delete my account</button>
</form>