To log the user out, the session values will be reset, the session data will be destroyed on the server, and the session cookie will be deleted.
<?php
// This is the logout page
include ('start.php');
// site URL (base for all redirections)
define ('BASE_URL', 'http://voyager.deanza.edu/~hso/php/lecture/php23/');
$url = BASE_URL . 'index.html';
if (isset($_SESSION['first_name'])) {
// logout
// Unset all of the session variables.
$_SESSION = array();
// If it's desired to kill the session, also delete the session cookie.
// Note: This will destroy the session, and not just the session data!
if (isset($_COOKIE[session_name()])) {
setcookie(session_name(), '', time()-42000, '/');
}
// Finally, destroy the session.
session_destroy();
}
else {
// delete the buffer
ob_end_clean();
// redirect
header("Location: $url");
}
echo " |