目錄
1、需求分析
2、解决方案
2.1 系统流程图" >2.1 系统流程图
2.2 PHPbookmark中的文件列表
3、实现数据库
4、实现基本的网站
4.1 login.php
4.2 bookmark_fns.php
5、实现用户身份验证
5.1 register_form.php" >5.1 register_form.php
5.2 register_new.php" >5.2 register_new.php
5.3 member.php" >5.3 member.php
5.4 logout.php" >5.4 logout.php
5.5 change_passwd.php" >5.5 change_passwd.php
5.6 forgot_paswd.php" >5.6 forgot_paswd.php
6、实现书签的存储和检索
6.1 add_bms.php" >6.1 add_bms.php
6.2 delete_bms.php" >6.2 delete_bms.php
6.3 recommend.php" >6.3 recommend.php
7、源代码
首頁 後端開發 php教程 7、源代码

7、源代码

Jun 13, 2016 pm 12:24 PM
html passwd php require

一个简单的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

PHPbookmarklogo图标



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 [email protected] identified by 'password';
登入後複製

4、实现基本的网站

4.1 login.php

<?php /** * @author switch * @copyright 2015 * 包含系统登录表单的页面 */    //require_once语句和require语句完全相同,唯一区别是PHP会检查该文件是否已经被包含过,如果是则不会再次包含。    require_once(&#39;bookmark_fns.php&#39;);   //应用程序的包含文件集合        do_html_header(&#39;&#39;); //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(&#39;data_valid_fns.php&#39;); //确认用户输入数据有效的函数    require_once(&#39;db_fns.php&#39;); // 连接数据库的函数    require_once(&#39;user_auth_fns.php&#39;);  //用户身份验证的函数    require_once(&#39;output_fns.php&#39;); //以HTML形式格式化输出的函数    require_once(&#39;url_fns.php&#39;);    //增加和删除书签的函数?>
登入後複製

5、实现用户身份验证

5.1 register_form.php

<?php /** * @author switch * @copyright 2015 * 系统中用户注册表单 */    //require_once语句和require语句完全相同,唯一区别是PHP会检查该文件是否已经被包含过,如果是则不会再次包含。    require_once(&#39;bookmark_fns.php&#39;);    do_html_header(&#39;User Registration&#39;);    //HTML标题        display_registeration_form();   //输出注册表单        do_html_footer();   //HTML页脚?>
登入後複製

5.2 register_new.php

<?php /** * @author switch * @copyright 2015 * 处理新注册信息的脚本 */    //require_once语句和require语句完全相同,唯一区别是PHP会检查该文件是否已经被包含过,如果是则不会再次包含。    require_once(&#39;bookmark_fns.php&#39;);        //创建变量    $email = $_POST[&#39;email&#39;];    $username = $_POST[&#39;username&#39;];    $passwd = $_POST[&#39;passwd&#39;];    $passwd2 = $_POST[&#39;passwd2&#39;];    //开启会话    session_start();        try    {        //检查表单是否填写满        if(!filled_out($_POST))        {            throw new exception(&#39;You have not filled the form out correctly - please go back and try again.&#39;);        }                //检查邮件地址是否有效        if(!valid_email($email))        {            throw new exception(&#39;That is not a vald email address. Please go back try again.&#39;);        }                //检查两次输入密码是否相同        if($passwd != $passwd2)        {            throw new exception(&#39;The passwords you entered do not match - please go back try again.&#39;);        }                //检查密码长度是否合格        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(&#39;bookmark_fns.php&#39;);    session_start();        //创建变量    $username = @$_POST[&#39;username&#39;];    $passwd = @$_POST[&#39;passwd&#39;];        if($username && $passwd)    {        try        {            login($username,$passwd);            //如果该用户在数据库中,则注册会话变量            $_SESSION[&#39;valid_user&#39;] = $username;        }        catch(exception $e)        {            //登录不成功            do_html_header(&#39;Problem:&#39;);            echo &#39;You could not be logged in. You must be logged in to view this page.&#39;;            do_html_URL(&#39;login.php&#39;,&#39;Login&#39;);            do_html_footer();            exit;        }    }        do_html_header(&#39;Home&#39;);    check_valid_user();        //获取用户的书签    if($url_array = get_user_urls($_SESSION[&#39;valid_user&#39;]))        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(&#39;bookmark_fns.php&#39;);    session_start();    $old_user = $_SESSION[&#39;valid_user&#39;];        //注销会话变量    unset($_SESSION[&#39;valid_user&#39;]);    $result_dest = session_destroy();        do_html_header(&#39;Logging Out&#39;);        if(!empty($old_user))    {        if($result_dest)    //登出成功        {            echo &#39;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(&#39;bookmark_fns.php&#39;);    session_start();    do_html_header(&#39;Changing password&#39;);        //创建变量    $old_passwd = $_POST[&#39;old_passwd&#39;];    $new_passwd = $_POST[&#39;new_passwd&#39;];    $new_passwd2 = $_POST[&#39;new_passwd2&#39;];        try    {        check_valid_user();        if(!filled_out($_POST))            throw new exception(&#39;You have not filled out the form completely.Please try again.&#39;);                if($new_passwd != $new_passwd2)            throw new exception(&#39;Passwords entered were not the same. Not changed.&#39;);                    if((strlen($new_passwd) > 16) || (strlen($new_passwd) getMessage();    }    display_user_menu();    do_html_footer();?>
登入後複製

5.6 forgot_paswd.php

<?php /** * @author switch * @copyright 2015 * 重新设置遗忘密码的脚本 */    //require_once语句和require语句完全相同,唯一区别是PHP会检查该文件是否已经被包含过,如果是则不会再次包含。    require_once(&#39;bookmark_fns.php&#39;);    do_html_header("Resetting password");        //创建变量    $username = $_POST[&#39;username&#39;];        try    {        $passwd = reset_password($username);        notify_password($username,$passwd);        echo &#39;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(&#39;bookmark_fns.php&#39;);    session_start();        //创建变量    $new_url = $_POST[&#39;new_url&#39;];        do_html_header(&#39;Adding bookmarks&#39;);        try    {        check_valid_user(); //检查用户有效性        if(!filled_out($new_url))   //检查表单是否填写            throw new exception(&#39;Form not completely filled out.&#39;);        if(strstr($new_url,&#39;http://&#39;) === false)            $new_url = &#39;http://&#39;. $new_url;        if(!(@fopen($new_url,&#39;r&#39;))) //可以调用fopen()函数打开URL,如果能打开这个文件,则假定URL是有效的            throw new exception(&#39;Not a valid URL.&#39;);        add_bm($new_url);   //将URL添加到数据库中        echo &#39;Bookmark added.&#39;;        if($url_array = get_user_urls($_SESSION[&#39;valid_user&#39;]))            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(&#39;bookmark_fns.php&#39;);    session_start();        //创建变量    $del_me = @$_POST[&#39;del_me&#39;];    $valid_user = $_SESSION[&#39;valid_user&#39;];        do_html_header(&#39;Deleting bookmarks&#39;);    check_valid_user();        if(!filled_out($del_me))    //    {        echo &#39;<p>You have not chosen any bookmarks to delete.<br>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) .'.<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(&#39;bookmark_fns.php&#39;);    session_start();    do_html_header(&#39;Recommending URLs&#39;);    try    {        check_valid_user();        $urls = recommend_urls($_SESSION[&#39;valid_user&#39;]);        display_recommended_urls($urls);    }    catch(exception $e)    {        echo $e ->getMessage();    }    display_user_menu();    do_html_footer();?>
登入後複製

7、源代码

下载地址



版权声明:本文为博主原创文章,未经博主允许不得转载。

本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

<🎜>:泡泡膠模擬器無窮大 - 如何獲取和使用皇家鑰匙
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
北端:融合系統,解釋
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
Mandragora:巫婆樹的耳語 - 如何解鎖抓鉤
3 週前 By 尊渡假赌尊渡假赌尊渡假赌

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

熱門話題

Java教學
1665
14
CakePHP 教程
1424
52
Laravel 教程
1322
25
PHP教程
1269
29
C# 教程
1249
24
PHP和Python:比較兩種流行的編程語言 PHP和Python:比較兩種流行的編程語言 Apr 14, 2025 am 12:13 AM

PHP和Python各有優勢,選擇依據項目需求。 1.PHP適合web開發,尤其快速開發和維護網站。 2.Python適用於數據科學、機器學習和人工智能,語法簡潔,適合初學者。

PHP行動:現實世界中的示例和應用程序 PHP行動:現實世界中的示例和應用程序 Apr 14, 2025 am 12:19 AM

PHP在電子商務、內容管理系統和API開發中廣泛應用。 1)電子商務:用於購物車功能和支付處理。 2)內容管理系統:用於動態內容生成和用戶管理。 3)API開發:用於RESTfulAPI開發和API安全性。通過性能優化和最佳實踐,PHP應用的效率和可維護性得以提升。

PHP:網絡開發的關鍵語言 PHP:網絡開發的關鍵語言 Apr 13, 2025 am 12:08 AM

PHP是一種廣泛應用於服務器端的腳本語言,特別適合web開發。 1.PHP可以嵌入HTML,處理HTTP請求和響應,支持多種數據庫。 2.PHP用於生成動態網頁內容,處理表單數據,訪問數據庫等,具有強大的社區支持和開源資源。 3.PHP是解釋型語言,執行過程包括詞法分析、語法分析、編譯和執行。 4.PHP可以與MySQL結合用於用戶註冊系統等高級應用。 5.調試PHP時,可使用error_reporting()和var_dump()等函數。 6.優化PHP代碼可通過緩存機制、優化數據庫查詢和使用內置函數。 7

PHP的持久相關性:它還活著嗎? PHP的持久相關性:它還活著嗎? Apr 14, 2025 am 12:12 AM

PHP仍然具有活力,其在現代編程領域中依然佔據重要地位。 1)PHP的簡單易學和強大社區支持使其在Web開發中廣泛應用;2)其靈活性和穩定性使其在處理Web表單、數據庫操作和文件處理等方面表現出色;3)PHP不斷進化和優化,適用於初學者和經驗豐富的開發者。

PHP和Python:代碼示例和比較 PHP和Python:代碼示例和比較 Apr 15, 2025 am 12:07 AM

PHP和Python各有優劣,選擇取決於項目需求和個人偏好。 1.PHP適合快速開發和維護大型Web應用。 2.Python在數據科學和機器學習領域佔據主導地位。

PHP與其他語言:比較 PHP與其他語言:比較 Apr 13, 2025 am 12:19 AM

PHP適合web開發,特別是在快速開發和處理動態內容方面表現出色,但不擅長數據科學和企業級應用。與Python相比,PHP在web開發中更具優勢,但在數據科學領域不如Python;與Java相比,PHP在企業級應用中表現較差,但在web開發中更靈活;與JavaScript相比,PHP在後端開發中更簡潔,但在前端開發中不如JavaScript。

PHP和Python:解釋了不同的範例 PHP和Python:解釋了不同的範例 Apr 18, 2025 am 12:26 AM

PHP主要是過程式編程,但也支持面向對象編程(OOP);Python支持多種範式,包括OOP、函數式和過程式編程。 PHP適合web開發,Python適用於多種應用,如數據分析和機器學習。

PHP:處理數據庫和服務器端邏輯 PHP:處理數據庫和服務器端邏輯 Apr 15, 2025 am 12:15 AM

PHP在數據庫操作和服務器端邏輯處理中使用MySQLi和PDO擴展進行數據庫交互,並通過會話管理等功能處理服務器端邏輯。 1)使用MySQLi或PDO連接數據庫,執行SQL查詢。 2)通過會話管理等功能處理HTTP請求和用戶狀態。 3)使用事務確保數據庫操作的原子性。 4)防止SQL注入,使用異常處理和關閉連接來調試。 5)通過索引和緩存優化性能,編寫可讀性高的代碼並進行錯誤處理。

See all articles