/
logout.php
33 lines (24 loc) · 865 Bytes
/
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
<?php # Script 12.11 - logout.php #2
// This page lets the user logout.
// This version uses sessions.
session_start(); // Access the existing session.
// If no session variable exists, redirect the user:
if (!isset($_SESSION['user_id'])) {
// Need the functions:
require ('includes/login_functions.inc.php');
redirect_user();
} else { // Cancel the session:
$_SESSION = array(); // Clear the variables.
session_destroy(); // Destroy the session itself.
setcookie ('PHPSESSID', '', time()-3600, '/', '', 0, 0); // Destroy the cookie.
}
// Set the page title and include the HTML header:
$page_title = 'Logged Out!';
include ('./includes/header.html');
include('./includes/top.html');
// Print a customized message:
echo "<h1>Logged Out!</h1>
<p>You are now logged out!</p>";
include('./includes/bottom.html');
include ('./includes/footer.html');
?>