<?php /** * 将用户注销的脚本 */ //require_once语句和require语句完全相同,唯一区别是PHP会检查该文件是否已经被包含过,如果是则不会再次包含。 require_once('bookmark_fns.php'); session_start(); $old_user = $_SESSION['valid_user']; //注销会话变量 unset($_SESSION['valid_user']); $result_dest = session_destroy(); do_html_header('Logging Out'); if(!empty($old_user)) { if($result_dest) //登出成功 { echo 'Logged out.<br />'; do_html_URL('login.php','Login'); } else //不成功 { echo 'Could not log you out.<br />'; } } else { echo 'You were not logged in, and so have not been logged ot.<br />'; do_html_URL('login.php','Login'); } do_html_footer(); ?>
5.5 change_passwd.php
<?php /** * 修改数据库中用户密码的表单 */ //require_once语句和require语句完全相同,唯一区别是PHP会检查该文件是否已经被包含过,如果是则不会再次包含。 require_once('bookmark_fns.php'); session_start(); do_html_header('Changing password'); //创建变量 $old_passwd = $_POST['old_passwd']; $new_passwd = $_POST['new_passwd']; $new_passwd2 = $_POST['new_passwd2']; try { check_valid_user(); if(!filled_out($_POST)) throw new exception('You have not filled out the form completely.Please try again.'); if($new_passwd != $new_passwd2) throw new exception('Passwords entered were not the same. Not changed.'); if((strlen($new_passwd) > 16) || (strlen($new_passwd) < 6)) { throw new exception('New password must be between 6 and 16 characters. Try again.'); } //尝试修改 change_password($_SESSION['valid_user'],$old_passwd,$new_passwd); echo 'Password changed.'; } catch(exception $e) { echo $e ->getMessage(); } display_user_menu(); do_html_footer(); ?>
5.6 forgot_paswd.php
<?php /** * 重新设置遗忘密码的脚本 */ //require_once语句和require语句完全相同,唯一区别是PHP会检查该文件是否已经被包含过,如果是则不会再次包含。 require_once('bookmark_fns.php'); do_html_header("Resetting password"); //创建变量 $username = $_POST['username']; try { $passwd = reset_password($username); notify_password($username,$passwd); echo 'Your new password has been emailed to you.<br />'; } catch(exception $e) { echo 'Your password could not be reset - please try again later.'; } do_html_URL('login.php','Login'); do_html_footer(); ?>
6、实现书签的存储和检索
6.1 add_bms.php
<?php /** * 添加书签的表单 */ //require_once语句和require语句完全相同,唯一区别是PHP会检查该文件是否已经被包含过,如果是则不会再次包含。 require_once('bookmark_fns.php'); session_start(); //创建变量 $new_url = $_POST['new_url']; do_html_header('Adding bookmarks'); try { check_valid_user(); //检查用户有效性 if(!filled_out($new_url)) //检查表单是否填写 throw new exception('Form not completely filled out.'); if(strstr($new_url,'http://') === false) $new_url = 'http://'. $new_url; if(!(@fopen($new_url,'r'))) //可以调用fopen()函数打开URL,如果能打开这个文件,则假定URL是有效的 throw new exception('Not a valid URL.'); add_bm($new_url); //将URL添加到数据库中 echo 'Bookmark added.'; if($url_array = get_user_urls($_SESSION['valid_user'])) display_user_urls($url_array); } catch(exception $e) { echo $e ->getMessage(); } display_user_menu(); do_html_footer(); ?>
6.2 delete_bms.php
<?php /** * 从用户的书签列表中删除选定书签的脚本呢 */ //require_once语句和require语句完全相同,唯一区别是PHP会检查该文件是否已经被包含过,如果是则不会再次包含。 require_once('bookmark_fns.php'); session_start(); //创建变量 $del_me = @$_POST['del_me']; $valid_user = $_SESSION['valid_user']; do_html_header('Deleting bookmarks'); check_valid_user(); if(!filled_out($del_me)) // { echo '<p>You have not chosen any bookmarks to delete.<br />Please try again.</p>'; display_user_menu(); do_html_footer(); exit; } else { if(count($del_me) > 0) { foreach($del_me as $url) { if(delete_bm($valid_user,$url)) { echo 'Deleted '. htmlspecialchars($url) .'.<br />'; } else { echo 'Could not delete '. htmlspecialchars($url) .'.<br />'; } } } else { echo 'No bookmarks selected for deletion'; } } if($url_array = get_user_urls($valid_user)) { display_user_urls($url_array); } display_user_menu(); do_html_footer(); ?>
6.3 recommend.php