logout.php

The final ingredient in our social networking recipe is Example 21-12, logout.php, the logout page that closes a session and deletes any associated data and cookies. The result of calling up this program can be seen in Figure 21-8, where the user is now asked to click on a link that will take that user to the un-logged-in home page and remove the logged-in links from the top of the screen. Of course, you could write a JavaScript or PHP redirect to do this (probably a good idea if you wish to keep logging out looking clean).

Example 21-12. logout.php
<?php // logout.php
include_once 'header.php';

if (isset($_SESSION['user']))
{
    destroySession();
    echo "<div class='main'>You have been logged out. Please " .
         "<a href='index.php'>click here</a> to refresh the screen.";
}
else echo "<div class='main'><br />" .
          "You cannot log out because you are not logged in";
?>

<br /><br /></div></body></html>
The logout page