PHP bookmark system case
This article mainly introduces the case of PHP bookmark system. Interested friends can refer to it. I hope it will be helpful to everyone.
1. Requirements analysis
First, each user needs to be identified. There should be a verification mechanism.
Secondly, you need to save a single user's bookmarks. Users should be able to add and delete bookmarks.
Again, it is necessary to recommend sites to users that may be of interest to them based on what is known about them.
2. Solution2.1 System flow chart
3. Implement database
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. Implement basic website4.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页脚 ?>
<?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. Implement user authentication5.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页脚 ?>
<?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; } ?>
<?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(); ?>
<?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(); ?>
<?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(); ?>
<?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. Implement bookmark storage and retrieval6.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(); ?>
<?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(); ?>
<?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(); ?>
Summary: That’s it The entire content of the article is hoped to be helpful to everyone's study.
Related recommendations:
Examples of access methods for class attributes and class static variables in PHP
php cookie working principle and detailed explanation of examples
PHP uses socket to simulate POST method
The above is the detailed content of PHP bookmark system case. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7
