Specifications
Logging Out
You might have noticed that there is a link marked “Logout” on the menu in Figure 24.6. This
is a link to the logout.php script. The code for this script is shown in Listing 24.14.
LISTING 24.14 logout.php—This Script Ends a User Session
<?
// include function files for this application
require_once(“bookmark_fns.php”);
session_start();
$old_user = $valid_user; // store to test if they *were* logged in
$result_unreg = session_unregister(“valid_user”);
$result_dest = session_destroy();
// start output html
do_html_header(“Logging Out”);
if (!empty($old_user))
{
if ($result_unreg && $result_dest)
{
// if they were logged in and are now logged out
echo “Logged out.<br>”;
do_html_url(“login.php”, “Login”);
}
else
{
// they were logged in and could not be logged out
echo “Could not log you out.<br>”;
}
}
else
{
// if they weren’t logged in but came to this page somehow
echo “You were not logged in, and so have not been logged out.<br>”;
do_html_url(“login.php”, “Login”);
}
do_html_footer();
?>
Again, you might find that this code looks familiar. That’s because it is based on the code we
wrote in Chapter 20.
Building Practical PHP and MySQL Projects
P
ART V
518
30 7842 ch24 3/6/01 3:34 PM Page 518










