백엔드 개발 PHP 튜토리얼 PHP在线书签系统分享_php实例

PHP在线书签系统分享_php实例

Jun 07, 2016 pm 05:09 PM
php

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

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

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

2.2 PHPbookmark中的文件列表


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

<&#63;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页脚 
&#63;> 
로그인 후 복사

4.2 bookmark_fns.php

<&#63;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');  //增加和删除书签的函数 
&#63;> 
로그인 후 복사

5、实现用户身份验证
5.1 register_form.php

<&#63;php 
 
/** 
 * 系统中用户注册表单 
 */ 
  //require_once语句和require语句完全相同,唯一区别是PHP会检查该文件是否已经被包含过,如果是则不会再次包含。 
  require_once('bookmark_fns.php'); 
  do_html_header('User Registration');  //HTML标题 
   
  display_registeration_form();  //输出注册表单 
   
  do_html_footer();  //HTML页脚 
&#63;> 
로그인 후 복사

5.2 register_new.php

<&#63;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; 
  } 
&#63;> 
로그인 후 복사

5.3 member.php

<&#63;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(); 
&#63;> 
로그인 후 복사

5.4 logout.php

<&#63;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(); 
&#63;> 
로그인 후 복사

5.5 change_passwd.php

<&#63;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(); 
&#63;> 
로그인 후 복사

5.6 forgot_paswd.php

<&#63;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(); 
&#63;> 
로그인 후 복사

6、实现书签的存储和检索
6.1 add_bms.php

<&#63;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(); 
&#63;> 
로그인 후 복사

6.2 delete_bms.php

<&#63;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(); 
&#63;> 
로그인 후 복사

6.3 recommend.php

<&#63;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(); 
&#63;> 
로그인 후 복사

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

본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

AI Hentai Generator

AI Hentai Generator

AI Hentai를 무료로 생성하십시오.

뜨거운 도구

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전

SublimeText3 중국어 버전

중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)

CakePHP 프로젝트 구성 CakePHP 프로젝트 구성 Sep 10, 2024 pm 05:25 PM

이번 장에서는 CakePHP의 환경 변수, 일반 구성, 데이터베이스 구성, 이메일 구성에 대해 알아봅니다.

Ubuntu 및 Debian용 PHP 8.4 설치 및 업그레이드 가이드 Ubuntu 및 Debian용 PHP 8.4 설치 및 업그레이드 가이드 Dec 24, 2024 pm 04:42 PM

PHP 8.4는 상당한 양의 기능 중단 및 제거를 통해 몇 가지 새로운 기능, 보안 개선 및 성능 개선을 제공합니다. 이 가이드에서는 Ubuntu, Debian 또는 해당 파생 제품에서 PHP 8.4를 설치하거나 PHP 8.4로 업그레이드하는 방법을 설명합니다.

CakePHP 날짜 및 시간 CakePHP 날짜 및 시간 Sep 10, 2024 pm 05:27 PM

cakephp4에서 날짜와 시간을 다루기 위해 사용 가능한 FrozenTime 클래스를 활용하겠습니다.

CakePHP 파일 업로드 CakePHP 파일 업로드 Sep 10, 2024 pm 05:27 PM

파일 업로드 작업을 위해 양식 도우미를 사용할 것입니다. 다음은 파일 업로드의 예입니다.

CakePHP 라우팅 CakePHP 라우팅 Sep 10, 2024 pm 05:25 PM

이번 장에서는 라우팅과 관련된 다음과 같은 주제를 학습하겠습니다.

CakePHP 토론 CakePHP 토론 Sep 10, 2024 pm 05:28 PM

CakePHP는 PHP용 오픈 소스 프레임워크입니다. 이는 애플리케이션을 훨씬 쉽게 개발, 배포 및 유지 관리할 수 있도록 하기 위한 것입니다. CakePHP는 강력하고 이해하기 쉬운 MVC와 유사한 아키텍처를 기반으로 합니다. 모델, 뷰 및 컨트롤러 gu

PHP 개발을 위해 Visual Studio Code(VS Code)를 설정하는 방법 PHP 개발을 위해 Visual Studio Code(VS Code)를 설정하는 방법 Dec 20, 2024 am 11:31 AM

VS Code라고도 알려진 Visual Studio Code는 모든 주요 운영 체제에서 사용할 수 있는 무료 소스 코드 편집기 또는 통합 개발 환경(IDE)입니다. 다양한 프로그래밍 언어에 대한 대규모 확장 모음을 통해 VS Code는

CakePHP 유효성 검사기 만들기 CakePHP 유효성 검사기 만들기 Sep 10, 2024 pm 05:26 PM

컨트롤러에 다음 두 줄을 추가하면 유효성 검사기를 만들 수 있습니다.

See all articles