PHP在线书签系统分享


Posted in PHP onJanuary 04, 2016

本文为大家分享了PHP在线书签系统,感兴趣的小伙伴们可以参考一下

1、需求分析
首先,需要识别每个用户。应该有验证机制。
其次,需要保存单个用户的书签。用户应该能够添加和删除书签。
再次,需要根据对他们的了解,向用户建议他们可能感兴趣的站点。

2、解决方案
2.1 系统流程图

PHP在线书签系统分享

2.2 PHPbookmark中的文件列表

PHP在线书签系统分享

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

4、实现基本的网站
4.1 login.php

<?php 
 
/** 
 * 包含系统登录表单的页面 
 */ 
  //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 
 
/** 
 * 应用程序的包含文件集合 
 */ 
  //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 
 
/** 
 * 系统中用户注册表单 
 */ 
  //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 
 
/** 
 * 处理新注册信息的脚本 
 */ 
  //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 
 
/** 
 * 用户的主页面,包含该用户所有的当前书签 
 */ 
  //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 
 
/** 
 * 将用户注销的脚本 
 */ 
  //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 
 
/** 
 * 修改数据库中用户密码的表单 
 */ 
  //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 
 
/** 
 * 重新设置遗忘密码的脚本 
 */ 
  //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 
 
/** 
 * 添加书签的表单 
 */ 
  //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 
 
/** 
 * 从用户的书签列表中删除选定书签的脚本呢 
 */ 
  //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 
 
/** 
 * 基于用户以前的操作,推荐用户可能感兴趣的书签 
 */ 
  //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(); 
?>

以上就是PHP在线书签系统的详细代码,希望对大家的学习有所帮助。

PHP 相关文章推荐
通过文字传递创建的图形按钮
Oct 09 PHP
IIS+PHP+MySQL+Zend配置 (视频教程)
Dec 13 PHP
PHP 字符串 小常识
Jun 05 PHP
关于php mvc开发模式的感想
Jun 28 PHP
PHP文件操作实现代码分享
Sep 01 PHP
PHP网页游戏学习之Xnova(ogame)源码解读(十二)
Jun 25 PHP
windows中为php安装mongodb与memcache
Jan 06 PHP
php文件读取方法实例分析
Jun 20 PHP
PHP使用file_get_content设置头信息的方法
Feb 14 PHP
PHP设计模式之观察者模式定义与用法示例
Aug 04 PHP
PHP 7.4 新语法之箭头函数实例详解
May 09 PHP
PHP defined()函数的使用图文详解
Jul 20 PHP
PHP数据库连接mysql与mysqli对比分析
Jan 04 #PHP
非常重要的php正则表达式详解
Jan 04 #PHP
PHP 下载文件时如何自动添加bom头及解释BOM头和去掉bom头的方法
Jan 04 #PHP
隐藏Nginx或Apache以及PHP的版本号的方法
Jan 03 #PHP
PHP 读取文本文件内容并分页显示
Jan 02 #PHP
php实现概率性随机抽奖代码
Jan 02 #PHP
php实现给一张图片加上水印效果
Jan 02 #PHP
You might like
php简单随机字符串生成方法示例
2017/04/19 PHP
js常用函数 不错
2006/09/08 Javascript
javascript温习的一些笔记 基础常用知识小结
2011/06/22 Javascript
ie9 提示'console' 未定义问题的解决方法
2014/03/20 Javascript
JavaScript日期时间格式化函数分享
2014/05/05 Javascript
AngularJS实现全选反选功能
2015/12/08 Javascript
angular route中使用resolve在uglify压缩后问题解决
2016/09/21 Javascript
如何判断出一个js对象是否一个dom对象
2016/11/24 Javascript
js canvas实现适用于移动端的百分比仪表盘dashboard
2017/07/18 Javascript
jQuery实现简单的计时器功能实例分析
2017/08/29 jQuery
详解如何在vue-cli中使用vuex
2018/08/07 Javascript
详解Vue中数组和对象更改后视图不刷新的问题
2018/09/21 Javascript
element-ui table span-method(行合并)的实现代码
2018/12/20 Javascript
vue el-table实现行内编辑功能
2019/12/11 Javascript
ant-design-vue中tree增删改的操作方法
2020/11/03 Javascript
如何实现vue的tree组件
2020/12/03 Vue.js
[01:28]2014DOTA2国际邀请赛中国区预选赛四大豪门直升机抵达会场
2014/05/24 DOTA
在Debian下配置Python+Django+Nginx+uWSGI+MySQL的教程
2015/04/25 Python
老生常谈Python进阶之装饰器
2017/05/11 Python
Python+OpenCV目标跟踪实现基本的运动检测
2018/07/10 Python
在Mac上删除自己安装的Python方法
2018/10/29 Python
Python shelve模块实现解析
2019/08/28 Python
python设置随机种子实例讲解
2019/09/12 Python
使用tkinter实现三子棋游戏
2021/02/25 Python
CSS3 优势以及网页设计师如何使用CSS3技术
2009/07/29 HTML / CSS
CSS3 实现弹跳的小球动画
2020/10/26 HTML / CSS
html5图片上传预览示例分享
2014/04/14 HTML / CSS
在C++ 程序中调用被C 编译器编译后的函数,为什么要加extern "C"
2014/08/09 面试题
2014年公务员思想汇报范文:全心全意为人民服务
2014/03/06 职场文书
成龙洗发水广告词
2014/03/14 职场文书
《与朱元思书》的教学反思
2014/04/17 职场文书
党员领导干部承诺书
2014/05/28 职场文书
走群众路线剖析材料
2014/10/09 职场文书
辣妈辣妹观后感
2015/06/10 职场文书
幼儿园中班班级总结
2015/08/10 职场文书
python通过新建环境安装tfx的问题
2022/05/20 Python