搜索

7、源代码

Jun 13, 2016 pm 12:24 PM
htmlpasswdphprequire

一个简单的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
PHP中的依赖注入:避免常见的陷阱PHP中的依赖注入:避免常见的陷阱May 16, 2025 am 12:17 AM

DependencyInjection(DI)inPHPenhancescodeflexibilityandtestabilitybydecouplingdependencycreationfromusage.ToimplementDIeffectively:1)UseDIcontainersjudiciouslytoavoidover-engineering.2)Avoidconstructoroverloadbylimitingdependenciestothreeorfour.3)Adhe

如何加快PHP网站:性能调整如何加快PHP网站:性能调整May 16, 2025 am 12:12 AM

到Improveyourphpwebsite的实力,UsEthestertate:1)emplastOpCodeCachingWithOpcachetCachetOspeedUpScriptInterpretation.2)优化的atabasequesquesquesquelies berselectingOnlynlynnellynnessaryfields.3)usecachingsystemssslikeremememememcachedisemcachedtoredtoredtoredsatabaseloadch.4)

通过PHP发送大规模电子邮件:有可能吗?通过PHP发送大规模电子邮件:有可能吗?May 16, 2025 am 12:10 AM

是的,itispossibletosendMassemailswithp.1)uselibrarieslikeLikePhpMailerorSwiftMailerForeffitedEmailSending.2)enasledeLaysBetemailStoavoidSpamflagssspamflags.3)sylectynamicContentToimpovereveragement.4)

PHP中依赖注入的目的是什么?PHP中依赖注入的目的是什么?May 16, 2025 am 12:10 AM

DependencyInjection(DI)inPHPisadesignpatternthatachievesInversionofControl(IoC)byallowingdependenciestobeinjectedintoclasses,enhancingmodularity,testability,andflexibility.DIdecouplesclassesfromspecificimplementations,makingcodemoremanageableandadapt

如何使用PHP发送电子邮件?如何使用PHP发送电子邮件?May 16, 2025 am 12:03 AM

使用PHP发送电子邮件的最佳方法包括:1.使用PHP的mail()函数进行基本发送;2.使用PHPMailer库发送更复杂的HTML邮件;3.使用SendGrid等事务性邮件服务提高可靠性和分析能力。通过这些方法,可以确保邮件不仅到达收件箱,还能吸引收件人。

如何计算PHP多维数组的元素总数?如何计算PHP多维数组的元素总数?May 15, 2025 pm 09:00 PM

计算PHP多维数组的元素总数可以使用递归或迭代方法。1.递归方法通过遍历数组并递归处理嵌套数组来计数。2.迭代方法使用栈来模拟递归,避免深度问题。3.array_walk_recursive函数也能实现,但需手动计数。

PHP中do-while循环有什么特点?PHP中do-while循环有什么特点?May 15, 2025 pm 08:57 PM

在PHP中,do-while循环的特点是保证循环体至少执行一次,然后再根据条件决定是否继续循环。1)它在条件检查之前执行循环体,适合需要确保操作至少执行一次的场景,如用户输入验证和菜单系统。2)然而,do-while循环的语法可能导致新手困惑,且可能增加不必要的性能开销。

PHP中如何哈希字符串?PHP中如何哈希字符串?May 15, 2025 pm 08:54 PM

在PHP中高效地哈希字符串可以使用以下方法:1.使用md5函数进行快速哈希,但不适合密码存储。2.使用sha256函数提高安全性。3.使用password_hash函数处理密码,提供最高安全性和便捷性。

See all articles

热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

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

北端:融合系统,解释
1 个月前By尊渡假赌尊渡假赌尊渡假赌
Mandragora:巫婆树的耳语 - 如何解锁抓钩
4 周前By尊渡假赌尊渡假赌尊渡假赌
<🎜>掩盖:探险33-如何获得完美的色度催化剂
2 周前By尊渡假赌尊渡假赌尊渡假赌

热工具

安全考试浏览器

安全考试浏览器

Safe Exam Browser是一个安全的浏览器环境,用于安全地进行在线考试。该软件将任何计算机变成一个安全的工作站。它控制对任何实用工具的访问,并防止学生使用未经授权的资源。

WebStorm Mac版

WebStorm Mac版

好用的JavaScript开发工具

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

螳螂BT

螳螂BT

Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。