PHP Online Bookmark system Sharing _php Example

Source: Internet
Author: User

This article for everyone to share the PHP online bookmark system, interested in the small partners can refer to

1. Demand Analysis
First, you need to identify each user. There should be a validation mechanism.
Second, you need to save a bookmark for a single user. Users should be able to add and remove bookmarks.
Again, you need to suggest to the user what sites they might be interested in, based on their understanding.

2. Solution
2.1 System Flow chart

List of files in 2.2 Phpbookmark


3, the implementation of the database

Create database bookmarks; 
Use bookmarks; 
 
CREATE TABLE User ( 
 username varchar () primary key, 
 passwd char not NULL, 
 email varchar (MB) Not Null
   ); 
 
CREATE TABLE Bookmark ( 
 username varchar NOT NULL, 
 bm_url varchar (255) is not NULL, 
 index (username), C14/>index (Bm_url) 
); 
 
Grant SELECT, INSERT, UPDATE, delete on 
bookmarks.* to 
bm_user@localhost identified by ' password '; 

4, the realization of the basic website
4.1 login.php

<?php 
 
/** 
 * Contains the page of the system login 
 form 
  /The//require_once statement is identical to the Require statement, except that PHP checks that the file has been included and, if so, does not include it again. 
  require_once (' bookmark_fns.php ');  The application contains a collection of files 
   
  do_html_header (');//html header 
   
  Display_site_info ();//html site Information 
  display_login_form ();// HTML login Information 
   
  do_html_footer ();  HTML Footer 
?> 

4.2 bookmark_fns.php

<?php 
 
/** 
 * Application contains a collection of 
 files 
  ///require_once statements and require statements 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 (' data_valid_fns.php ');//Confirm user input data valid function 
  require_once (' db_fns.php ');//function 
  to connect to database Require_once (' user_auth_fns.php '); User authentication function 
  require_once (' output_fns.php ');//Format the output function in HTML 
  require_once (' url_fns.php ');  Add and remove functions for bookmarks 
?> 

5. Implement user authentication
5.1 register_form.php

<?php 
 
/** 
 * System in the user registration form 
 /* * 
  //require_once Statements and require statements are exactly the same, the only difference is that PHP will check whether the file has been included, if it is not 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/** * Script for new registrations///require_once statements and require statements exactly the same, the only difference is that PHP will check whether the file has been included, if it is not included again. 
   
  Require_once (' bookmark_fns.php '); 
  Create variable $email = $_post[' email ']; 
  $username = $_post[' username ']; 
  $passwd = $_post[' passwd ']; 
 
  $passwd 2 = $_post[' passwd2 ']; 
   
  Open session session_start ();  try {//check to see if the form fills in full if (!filled_out ($_post)) {throw new Exception (' You have not filled the "form out 
    Correctly-please go back and try again. '); Check if the mail address is valid if (!valid_email ($email)) {throw new Exception (' That's not a vald email addres 
    S. Please go back try again. '); //Check two times input password is the same if ($passwd!= $passwd 2) {throw new Exception (' The passwords you entered do n 
    OT match-please go back try again. '); //Check password length is qualified if ((strlen ($PASSWD) < 6) | | 
    (strlen ($PASSWD) > 16)) {Throw new Exception (' Your password must be between 6 and characters PleASE go back and try again. '); 
     
    //Try registering register ($username, $email, $passwd); 
     
    Register Session Variable $_session[' valid_user ' = $username; Provides member page link Do_html_header (' Registration successful '); HTML title echo ' Your registration 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/** * User's main page, containing all of the user's current bookmark///require_once statement and require statement exactly the same, the only difference is that PHP will check 
  Check if the file has been included, and 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 unsuccessful Do_html_header (' Problem: '); Echo ' You could is logged in. 
      You are must be logged into view this page. ' 
      Do_html_url (' login.php ', ' login '); 
      Do_html_footer (); 
    Exit 
  } do_html_header (' home '); 
   
  Check_valid_user (); 
  Gets the user's bookmark if ($url _array = Get_user_urls ($_session[' Valid_user ')) Display_user_urls ($url _array); 
 
  Get user menu option Display_user_menu (); 
Do_html_footer (); ?> 

5.4 logout.php

<?php 
 
/** 
 * The script that logs a user out of the 
  //require_once statement is exactly the same as the Require statement, except that PHP checks that the file has already been included and, if so, does not include it again. 
  require_once (' bookmark_fns.php '); 
  Session_Start (); 
  $old _user = $_session[' Valid_user ']; 
   
  Unregister Session variable 
  unset ($_session[' valid_user ')); 
  $result _dest = Session_destroy (); 
   
  Do_html_header (' Logging out '); 
   
  if (!empty ($old _user)) 
  { 
    if ($result _dest)  //Logout success 
    { 
      echo ' logged out.<br/> '; 
      Do_html_url (' login.php ', ' login '); 
    } 
    else  //unsuccessful 
    { 
      echo ' could not log for you out.<br/> '; 
    } 
  } 
  else 
  { 
    echo ' 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/** * The form///require_once statement that modifies a user's password in the database is exactly the same as the Require statement, except that PHP checks that the file has been included and, if so, does not include it 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 characters. 
    Try again. '); 
    //Attempt 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 script for forgotten passwords 
  ///require_once statements and require statements exactly the same, the only difference is that PHP will check whether the file has been included, if it is not 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. '; 
  } 
  Do_html_url (' login.php ', ' login '); 
  Do_html_footer (); 
? > 

6, the realization of bookmark storage and retrieval
6.1 add_bms.php

<?php 
 
/** 
 * Add a bookmark form * * * 
  //require_once statement is exactly the same as the Require statement, except that PHP checks whether the file has already been included and, if so, does not include it 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 the user validity 
    if (!filled_out ($new _url))  //Check whether 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, and if you can open the file, assume the URL is a valid 
      throw new exception (' Not a valid URL. '); 
    ADD_BM ($new _url);  Add a 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/** * Remove the selected bookmark from the user's bookmarks list. The * *//require_once statement is exactly the same as the Require statement, except that PHP checks that the file has been included and, if so, does not include it 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 no bookmarks to delete.<br try A 
    Gain.</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

<?php 
 
/** 
 * Based on the user's previous operations, the recommended user may be interested in bookmarks 
  ///require_once statements and require statements 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 (' 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 PHP online bookmark system Detailed code, I hope 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.