<?php # Script 16.9 - logout.php
// This is the logout page for the site

require_once ('includes/config.inc.php'); 
//start the page
$page_title = 'Logout';
include ('includes/headr.php');

// If no username session variable exists, redirect the user:
if (!isset($_SESSION['username'])) {

	$url = 'home.php'; // Define the URL.
	ob_end_clean(); // Delete the buffer.
	header("Location: $url");
	exit(); // Quit the script.
	
} else { // Log out the user.

	$_SESSION = array(); // Destroy the variables.
	session_destroy(); // Destroy the session itself.
	setcookie (session_name(), '', time()-300); // Destroy the cookie.
	$url = 'home.php'; // Define the URL.
	header("Location: $url");

}


// Print a customized message:
//echo '<h3>You are now logged out.</h3>';

//include ('includes/footer.html');
?>