PHP online bookmarks _ PHP-php Tutorial

Source: Internet
Author: User
Tags php online
This article mainly introduces the PHP online bookmarking system, analyzes system requirements, proposes solutions, establishes databases, and implements the basic website framework, you can refer to this article to share with us the PHP online bookmarks system. For more information, see

1. requirement analysis
First, you need to identify each user. There should be a verification mechanism.
Second, you need to save the bookmarks of a single user. Users should be able to add and delete bookmarks.
Once again, you need to advise the users of the sites they may be interested in based on their knowledge.

2. solutions
2.1 system flowchart

2.2 File list in PHPbookmark


3. implement databases

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, delete on bookmarks.* to bm_user@localhost identified by 'password'; 

4. implement basic websites
4.1 login. php

<? Php/*** page containing the system logon form * // The require_once statement is identical to the require statement. The only difference is that PHP checks whether the file has been included, if yes, it will not be included again. Require_once ('bookmark _ fns. php '); // contains the do_html_header ('') file set of the application; // The HTML title display_site_info (); // The HTML site information display_login_form (); // HTML login information do_html_footer (); // HTML footer?>

4.2 bookmark_fns.php

<? Php/*** contains the file set of the application * // The require_once statement is identical to the require statement. The only difference is that PHP checks whether the file has been included, if yes, it will not be included again. Require_once ('data _ valid_fns.php '); // The require_once ('Db _ fns. php '); // The database connection function require_once ('User _ auth_fns.php'); // The require_once ('output _ fns. php '); // format the output function require_once ('URL _ fns. php '); // add and delete bookmarks?>

5. implement user authentication
5.1 register_form.php

<? In php/*** system, the user registry form * // The require_once statement is identical to the require statement. The only difference is that PHP checks whether the file has been included, if yes, it will not be included again. Require_once ('bookmark _ fns. php '); do_html_header ('User registration'); // HTML title display_registeration_form (); // output registry ticket do_html_footer (); // HTML footer?>

5.2 register_new.php

<? Php/*** script for processing new registration information * // The require_once statement is identical to the require statement. The only difference is that PHP checks whether the file has been included, if yes, it will not be included again. Require_once ('bookmark _ fns. php '); // create the variable $ email =$ _ POST ['email']; $ username =$ _ POST ['username']; $ passwd =$ _ POST ['passwd']; $ passwd2 =$ _ POST ['passwd2 ']; // enable session session_start (); try {// check whether the form is full if (! Filled_out ($ _ POST) {throw new exception ('You have not filled the form out correctly-please go back and try again. ');} // check whether 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 whether the two passwords are the same if ($ passwd! = $ Passwd2) {throw new exception ('The passwords you entered do not match-please go back try again. ');} // check whether the password length is qualified if (strlen ($ passwd) <6) | (strlen ($ passwd)> 16 )) {throw new exception ('Your password must be between 6 and 16 characters Please go back and try again. ');} // try to register ($ username, $ email, $ passwd); // register the SESSION variable $ _ SESSION ['valid _ user'] = $ username; // provide the Member Page link do_html_header ('Regis Tration successful '); // HTML title echo 'Your registry was successful. Go to the members page to start setting up Your bookmarks! '; // Output URL do_html_URL ('member. php ', 'Go to members page'); // HTML footer do_html_footer (); // HTML footer} catch (exception $ e) {do_html_header ('problem :'); echo $ e-> getMessage (); do_html_footer (); exit ;}?>

5.3 member. php

<? Php/*** on the user's home page, including all the current bookmarks of the user * // The require_once statement is identical with the require statement, the only difference is that PHP will check whether the file has been included, and if so, it will not include it again. Require_once ('bookmark _ fns. php '); session_start (); // create the 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) {// do_html_header ('problem: ') when the logon fails :'); echo 'You could not be logged in. you must be logged in to view this page. '; do_html_URL ('login. php', 'L Ogin '); do_html_footer (); exit ;}} do_html_header ('Home'); check_valid_user (); // obtain the user's bookmarks if ($ url_array = get_user_urls ($ _ SESSION ['valid _ user']) display_user_urls ($ url_array ); // obtain the user menu options display_user_menu (); do_html_footer ();?>

5.4 logout. php

<? Php/*** deregister the user's script * // The require_once statement is exactly the same as the require statement. The only difference is that PHP checks whether the file has been included, if yes, it will not be included again. Require_once ('bookmark _ fns. php '); session_start (); $ old_user = $ _ SESSION ['valid _ user']; // unset the logout SESSION variable ($ _ SESSION ['valid _ user']); $ result_dest = session_destroy (); do_html_header ('logging out'); if (! Empty ($ old_user) {if ($ result_dest) // logout successful {echo 'loged' out.
'; Do_html_URL ('login. php', 'login');} else // failed {echo 'could not log you out.
';}} Else {echo' You were not logged in, and so have not been logged ot.
'; Do_html_URL ('login. php', 'login');} do_html_footer ();?>

5.5 change_passwd.php

<? Php/*** form for modifying the user password in the database * // The require_once statement is identical to the require statement. The only difference is that PHP checks whether the file has been included, if yes, it will not be included again. Require_once ('bookmark _ fns. php '); session_start (); do_html_header ('changing password'); // create the 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); echo 'password changed. ';} catch (exception $ e) {echo $ e-> getMessage ();} display_user _ Menu (); do_html_footer () ;?>

5.6 forgot_paswd.php

<? Php/*** reset the password-forgotten script * // The require_once statement is identical to the require statement. The only difference is that PHP checks whether the file has been included, if yes, it will not be included again. Require_once ('bookmark _ fns. php '); do_html_header ("Resetting password"); // create the variable $ username =$ _ POST ['username']; try {$ passwd = reset_password ($ username ); policy_password ($ username, $ passwd); echo 'Your new password has been emailed to you.
';} Catch (exception $ e) {echo 'Your password cocould not be reset-please try again later. ';} do_html_URL ('login. php ', 'login'); do_html_footer ();?>

6. storing and Searching bookmarks
6.1 add_bms.php

<? Php/*** form for adding bookmarks * // The require_once statement is identical to the require statement. The only difference is that PHP checks whether the file has been included, if yes, it will not be included again. Require_once ('bookmark _ fns. php '); session_start (); // create variable $ new_url = $ _ POST ['new _ url']; do_html_header ('adding bookmark'); try {check_valid_user (); // Check the user's validity if (! Filled_out ($ new_url) // check whether the Form is 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 you can open this file, it is assumed that the URL is a valid throw new exception ('not a valid URL. '); add_bm ($ new_url); // add the 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/*** delete the script for the selected bookmarks from the user's bookmarks list * // The require_once statement and require statement are identical, the only difference is that PHP will check whether the file has been included, and if so, it will not include it again. Require_once ('bookmark _ fns. php '); session_start (); // create the variable $ del_me =@$ _ POST ['Del _ me']; $ valid_user = $ _ SESSION ['valid _ user']; do_html_header ('ing ing bookmark'); check_valid_user (); if (! Filled_out ($ del_me) // {echo'

You have not chosen any bookmarks to delete.
Please try again.

'; 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 ). '.
';} Else {echo 'could not delete'. htmlspecialchars ($ url ).'.
';}} 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

<? Php/*** based on your previous operations, we recommend that you use bookmarks that may interest you * // The require_once statement is exactly the same as the require statement, the only difference is that PHP will check whether the file has been included, and if so, it will not include it 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 ();?>

The above is the detailed code of the PHP online bookmarking system, hoping to help you learn.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.