1. Demand analysis
First, each user needs to be identified. There should be a verification mechanism.
Second, you need to save individual user bookmarks. The user should be able to add and delete bookmarks.
Thirdly, we need to suggest sites that might be of interest to users based on what we know about them.
2. Solution
2.1 System flow chart
2.2 File list in PHPbookmark
file name |
description |
bookmarks.sql |
Create a database SQL statement for PHPbookmark |
login.php |
The page containing the system login form |
register_form.php |
User registration form in the system |
register_new.php |
Script to handle new registration information |
forgot_form.php |
The form that the user needs to fill out after forgetting the password |
forgot_passwd.php |
Script to reset forgotten password |
member.php |
The user’s home page, including all current bookmarks of the user |
add_bm_form.php |
Bookmarked form |
add_bms.php |
The script that actually adds the bookmark to the database |
delete_bms.php |
Delete the script of the selected bookmark from the user's bookmark list |
recommend.php |
Based on the user’s previous actions, recommend bookmarks that may be of interest to the user |
change_passwd_form.php |
The form to be filled out when the user changes the password |
change_passwd.php |
Modify the user password form in the database |
logout.php |
Script to log out the user |
bookmark_fns.php |
Application's include file collection |
data_valid_fns.php |
Function to confirm that the user input data is valid |
db_fns.php |
Function to connect to the database |
user_auth_fns.php |
User authentication function |
url_fns.php |
Functions for adding and deleting bookmarks |
output_fns.php |
Function to format output in HTML form |
bookmark.gif |
Logo icon for PHPbookmark |
3. Implement the database
create database bookmarks;use bookmarks;create table user (username varchar(16) primary key,passwd char(40) not null,email varchar(100) not null);create table bookmark (username varchar(16) not null,bm_URL varchar(255) not null,index (username),index (bm_URL));grant select, insert, update, deleteon bookmarks.*to bm_user@localhost identified by 'password';
4. Implement a basic website
4.1 login.php
<?php/** * @author switch * @copyright 2015 * The page containing the system login form*///The require_once statement and the require statement are exactly the same, the only difference is that PHP will check whether the file has been included, and if it is, Will not be included again. require_once('bookmark_fns.php'); //A collection of files included in the application do_html_header(''); //HTML title display_site_info(); // HTML site information display_login_form(); // HTML login information do_html_footer(); / /HTML footer?>
4.2 bookmark_fns.php
<?php/** * @author switch * @copyright 2015 * The application's include file collection*///require_once statement and require statement are exactly the same, the only difference is that PHP will check whether the file has been included, if it is Will not be included again. require_once('data_valid_fns.php'); //The function to confirm that the user input data is valid require_once('db_fns.php'); //The function to connect to the database require_once('user_auth_fns.php'); //The function of user authentication require_once ('output_fns.php'); //Function to format output in HTML form require_once('url_fns.php'); //Function to add and delete bookmarks?>
5. Implement user authentication
5.1 register_form.php
<?php/** * @author switch * @copyright 2015 * The user registration form in the system*///require_once statement and require statement are exactly the same, the only difference is that PHP will check whether the file has been included, if it is, it will not Will be included again. require_once('bookmark_fns.php'); do_html_header('User Registration'); //HTML title display_registeration_form(); //output registration form do_html_footer(); //HTML footer?>
5.2 register_new.php
<?php/** * @author switch * @copyright 2015 * The script that processes the new registration information*///The require_once statement and the require statement are exactly the same, the only difference is that PHP will check whether the file has been included, and if it is, Will not be included again. require_once('bookmark_fns.php');//Create variable $email = $_POST['email']; $username = $_POST['username']; $passwd = $_POST['passwd']; $passwd2 = $ _POST['passwd2'];//Open the session session_start();try{//Check if the form is filled out if(!filled_out($_POST)){throw new exception('You have not filled the form out correctly-please go back and try again.');}//Check if the email address is valid if(!valid_email($email)){throw new exception('That is not a vald email address. Please go back try again.');}/ /Check if the passwords entered twice are the same if($passwd != $passwd2){throw new exception('The passwords you entered do not match-please go back try again.');}//Check if the password length is qualified if( (strlen($passwd) <6) || (strlen($passwd)> 16)){throw new exception('
5.3 member.php
<?php/** * @author switch * @copyright 2015 * The user’s main page, which contains all of the user’s current bookmarks*///require_once statement and require statement are exactly the same, the only difference is that PHP will check whether the file has been Included, if it is, it will not be included again. require_once('bookmark_fns.php');session_start();//Create variable $username = @$_POST['username'];$passwd = @$_POST['passwd'];if($username && $passwd){ try{login($username,$passwd);//If the user is in the database, register the session variable $_SESSION['valid_user'] = $username;}catch(exception $e){//Login is unsuccessful do_html_header( 'Problem:');echo'You could not be logged in. You must be logged in to view this page.';do_html_URL('login.php','Login');do_html_footer();exit;))do_html_header( 'Home'); check_valid_user();//Get user bookmarks if($url_array = get_user_urls($_SESSION['valid_user'])) display_user_urls($url_array);//Get user menu options display_user_menu(); do_html_footer() ;?>
5.4 logout.php
<?php/** * @author switch * @copyright 2015 * The script to log out the user*///require_once statement and require statement are exactly the same, the only difference is that PHP will check whether the file has been included, if it is, it will not Will be included again. require_once('bookmark_fns.php');session_start();$old_user = $_SESSION['valid_user'];//Unregister the session variable unset($_SESSION['valid_user']);$result_dest = session_destroy();do_html_header(' Logging Out'); if(!empty($old_user)){if($result_dest) //Log out successfully{echo'Logged out.<br />';do_html_URL('login.php','Login'); }else //Unsuccessful{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/** * @author switch * @copyright 2015 * The form to modify the user password in the database*///The require_once statement and the require statement are exactly the same, the only difference is that PHP will check whether the file has been included, if it is It will not be included again. require_once('bookmark_fns.php');session_start();do_html_header('Changing password');//Create variable $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.');}//Try to modify change_password($_SESSION['valid_user'],$old_passwd,$new_passwd);
5.6 forgot_paswd.php
<?php/** * @author switch * @copyright 2015 * Script to reset the forgotten password*///require_once statement and require statement are exactly the same, the only difference is that PHP will check whether the file has been included, if it is Will not be included again. require_once('bookmark_fns.php');do_html_header("Resetting password");//Create variable $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. Realize bookmark storage and retrieval
6.1 add_bms.php
<?php/** * @author switch * @copyright 2015 * Form to add bookmarks*///require_once statement and require statement are exactly the same, the only difference is that PHP will check whether the file has been included, if it is, it will not Include again. require_once('bookmark_fns.php');session_start();//Create variable $new_url = $_POST['new_url']; do_html_header('Adding bookmarks'); try{check_valid_user(); //Check user validity if( !filled_out($new_url)) //Check if the form is filled throw new exception('Form not completely filled out.'); if(strstr($new_url,'http://') === false)$new_url = ' http://'. $new_url;if(!(@fopen($new_url,'r'))) //You can call the fopen() function to open the URL. If the file can be opened, the URL is assumed to be valid throw new exception('Not a valid URL.'); add_bm($new_url); //Add URL to the database 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/** * @author switch * @copyright 2015 * Delete the script of the selected bookmark from the user's bookmark list*///The require_once statement and the require statement are exactly the same, the only difference is that PHP will check whether the file is already Has been included, if it is, it will not be included again. require_once('bookmark_fns.php');session_start();//Create variable $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';
6.3 recommend.php
<?php/** * @author switch * @copyright 2015 * Based on the user's previous operations, recommend bookmarks that users may be interested in. *///The require_once statement and the require statement are exactly the same, the only difference is that PHP will check whether the file is already Has been included, if it is, it will not be included again. require_once('bookmark_fns.php');session_start();do_html_header('Recommending URLs');try{check_valid_user();$urls = recommend_urls($_SESSION['valid_user']);display_recommended_urls($urls);)catch( exception $e){echo $e ->getMessage();}display_user_menu();do_html_footer();?>