27.5.3 登出
我们可以已经注意到了,在图27-6所示的菜单选项上有一个标有"logout"的链接。该链接指向脚本logout.php。程序清单27-14给出了它的源代码。
程序清单27-14 logout.php——该脚本将结束一个用户会话
<?php
//include function files for this application
require_once('bookmark_fns.php');
session_start();
$old_user=$_SESSION['valid_user'];
//store to test if theywerelogged in
unset($_SESSION['valid_user']);
$result_dest=session_destroy();
//start output html
do_html_header('Logging Out');
if(!empty($old_user)){
if($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();
?>
我们会发现这段代码有些熟悉。因为它是根据第23章中编写的源代码而修改的。