forked from natyz/cs4640project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logout.php
50 lines (40 loc) · 1.47 KB
/
logout.php
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<!-- AUTHORS: WAN LI AND NATALIE ZHANG -->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
<title>PHP State Maintenance (Cookies)</title>
</head>
<?php session_start(); // make sessions available
?>
<body>
<?php
// DELETES COOKIES
if (count($_COOKIE) > 0) { // can also use sizeof($_COOKIE)
foreach ($_COOKIE as $key => $value) {
unset($_COOKIE[$key]); // remove param-value from server
//completley remov efrom client
setcookie($key, '', time() - 3600); // expire in past
}
//redirect
}
// DELETES SESSIONS
if (count($_SESSION) > 0) // Check if there are session variables
{
foreach ($_SESSION as $key => $value) {
// Deletes the variable (array element) where the value is stored in this PHP.
// However, the session object still remains on the server.
unset($_SESSION[$key]);
}
session_destroy(); // complete terminate the session instance
// redirect to the login page immediately
// header('Location: login.php');
// redirect with 5 seconds delay
echo "Successful logout. You will be redirected to the login page in 1 second.";
header('refresh:1; url=login.php');
}
?>
</body>
</html>