-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlogout.php
More file actions
31 lines (28 loc) · 816 Bytes
/
Copy pathlogout.php
File metadata and controls
31 lines (28 loc) · 816 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
29
30
31
<?php
// logout.php — ends session and returns to home or login
if (session_status() !== PHP_SESSION_ACTIVE) { session_start(); }
$ok = true;
if (!empty($_SESSION['csrf'])) {
$csrfgiven = $_GET['csrf'] ?? '';
if (!hash_equals($_SESSION['csrf'], (string)$csrfgiven)) {
$ok = false;
}
}
$_SESSION = [];
if (ini_get("session.use_cookies")) {
$params = session_get_cookie_params();
setcookie(session_name(), '', time() - 42000,
$params["path"], $params["domain"],
$params["secure"], $params["httponly"]
);
}
session_destroy();
$dest = 'welcome.php';
if (!empty($_GET['next'])) {
$n = (string)$_GET['next'];
if (strpos($n, '://') === false && strpos($n, '\\') === false) {
$dest = ltrim($n, '/');
}
}
header('Location: ' . $dest, true, 302);
exit;