一個簡單的PHP線上書籤系統,php線上書籤

來源:互聯網
上載者:User

一個簡單的PHP線上書籤系統,php線上書籤
1、需求分析   首先,需要識別每個使用者。應該有驗證機制。其次,需要儲存單個使用者的書籤。使用者應該能夠添加和刪除書籤。再次,需要根據對他們的瞭解,向使用者建議他們可能感興趣的網站。
2、解決方案2.1 系統流程圖2.2 PHPbookmark中的檔案清單

檔案名稱

描述

bookmarks.sql

建立PHPbookmark的資料庫SQL語句

login.php

包含系統登入表單的頁面

register_form.php

系統中使用者註冊表單

register_new.php

處理新註冊資訊的指令碼

forgot_form.php

使用者忘記密碼後需要填寫的表單

forgot_passwd.php

重新設定遺忘密碼的指令碼

member.php

使用者的首頁面,包含該使用者所有的當前書籤

add_bm_form.php

添加書籤的表單

add_bms.php

將書籤真正添加到資料庫中的指令碼

delete_bms.php

從使用者的書籤列表中刪除選定書籤的指令碼呢

recommend.php

基於使用者以前的操作,推薦使用者可能感興趣的書籤

change_passwd_form.php

使用者修改密碼時要填寫的表單

change_passwd.php

修改資料庫中使用者密碼的表單

logout.php

將使用者登出的指令碼

bookmark_fns.php

應用程式的包含檔案集合

data_valid_fns.php

確認使用者輸入資料有效函數

db_fns.php

串連資料庫的函數

user_auth_fns.php

使用者身分識別驗證的函數

url_fns.php

增加和刪除書籤的函數

output_fns.php

以HTML形式格式化輸出的函數

bookmark.gif

PHPbookmark的logo表徵圖



3、實現資料庫
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、實現基本的網站4.1 login.php
<?php/** * @author switch * @copyright 2015 * 包含系統登入表單的頁面 */    //require_once語句和require語句完全相同,唯一區別是PHP會檢查該檔案是否已經被包含過,如果是則不會再次包含。    require_once('bookmark_fns.php');   //應用程式的包含檔案集合        do_html_header(''); //HTML標題        display_site_info();//HTML網站資訊    display_login_form();//HTML登入資訊        do_html_footer();   //HTML頁尾?>

4.2 bookmark_fns.php
<?php/** * @author switch * @copyright 2015 * 應用程式的包含檔案集合 */    //require_once語句和require語句完全相同,唯一區別是PHP會檢查該檔案是否已經被包含過,如果是則不會再次包含。    require_once('data_valid_fns.php'); //確認使用者輸入資料有效函數    require_once('db_fns.php'); // 串連資料庫的函數    require_once('user_auth_fns.php');  //使用者身分識別驗證的函數    require_once('output_fns.php'); //以HTML形式格式化輸出的函數    require_once('url_fns.php');    //增加和刪除書籤的函數?>

5、實現使用者身分識別驗證5.1 register_form.php
<?php/** * @author switch * @copyright 2015 * 系統中使用者註冊表單 */    //require_once語句和require語句完全相同,唯一區別是PHP會檢查該檔案是否已經被包含過,如果是則不會再次包含。    require_once('bookmark_fns.php');    do_html_header('User Registration');    //HTML標題        display_registeration_form();   //輸出註冊表單        do_html_footer();   //HTML頁尾?>

5.2 register_new.php
<?php/** * @author switch * @copyright 2015 * 處理新註冊資訊的指令碼 */    //require_once語句和require語句完全相同,唯一區別是PHP會檢查該檔案是否已經被包含過,如果是則不會再次包含。    require_once('bookmark_fns.php');        //建立變數    $email = $_POST['email'];    $username = $_POST['username'];    $passwd = $_POST['passwd'];    $passwd2 = $_POST['passwd2'];    //開啟會話    session_start();        try    {        //檢查表單是否填寫滿        if(!filled_out($_POST))        {            throw new exception('You have not filled the form out correctly - please go back and try again.');        }                //檢查郵件地址是否有效        if(!valid_email($email))        {            throw new exception('That is not a vald email address. Please go back try again.');        }                //檢查兩次輸入密碼是否相同        if($passwd != $passwd2)        {            throw new exception('The passwords you entered do not match - please go back try again.');        }                //檢查密碼長度是否合格        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.');        }                //嘗試註冊        register($username,$email,$passwd);                //註冊會話變數        $_SESSION['valid_user'] = $username;                //提供成員頁面連結        do_html_header('Registration successful');  //HTML標題        echo 'Your registration was successful.Go to the members page to start setting up your bookmarks!'; //輸出URL        do_html_URL('member.php','Go to members page'); //HTML頁尾        do_html_footer();   //HTML頁尾    }    catch(exception $e)    {        do_html_header('Problem:');        echo $e->getMessage();        do_html_footer();        exit;    }?>

5.3 member.php
<?php/** * @author switch * @copyright 2015 * 使用者的首頁面,包含該使用者所有的當前書籤 */    //require_once語句和require語句完全相同,唯一區別是PHP會檢查該檔案是否已經被包含過,如果是則不會再次包含。    require_once('bookmark_fns.php');    session_start();        //建立變數    $username = @$_POST['username'];    $passwd = @$_POST['passwd'];        if($username && $passwd)    {        try        {            login($username,$passwd);            //如果該使用者在資料庫中,則註冊會話變數            $_SESSION['valid_user'] = $username;        }        catch(exception $e)        {            //登入不成功            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();        //擷取使用者的書籤    if($url_array = get_user_urls($_SESSION['valid_user']))        display_user_urls($url_array);    //擷取使用者菜單選項    display_user_menu();    do_html_footer();?>

5.4 logout.php
<?php/** * @author switch * @copyright 2015 * 將使用者登出的指令碼 */    //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/** * @author switch * @copyright 2015 * 修改資料庫中使用者密碼的表單 */    //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/** * @author switch * @copyright 2015 * 重新設定遺忘密碼的指令碼 */    //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/** * @author switch * @copyright 2015 * 添加書籤的表單 */    //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/** * @author switch * @copyright 2015 * 從使用者的書籤列表中刪除選定書籤的指令碼呢 */    //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
<?php/** * @author switch * @copyright 2015 * 基於使用者以前的操作,推薦使用者可能感興趣的書籤 */    //require_once語句和require語句完全相同,唯一區別是PHP會檢查該檔案是否已經被包含過,如果是則不會再次包含。    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();?>

7、原始碼


著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.