当前位置:网站首页>PHP website design ideas
PHP website design ideas
2022-07-25 14:08:00 【The goal is technology house】
This article is about 《PHP and MySQL Web Development》 The first 5 edition 27 Summary of the project in Chapter .
1. Analyze the required functions
List the main functional modules : Sign in 、 register 、 Forget the password 、 Reset password 、 Log out 、 Bookmark browsing 、 Bookmarks added 、 Bookmark deletion 、 Bookmark recommendation
Determine the sequential transfer relationship between modules :

2. Disassemble the required modules
Separate the logic and content of the module :
- The content is written in function_form.php in
- Logic is written in function.php in
Set up special files for :
- Connect to database
- Input data verification
- User authentication
- Browser output
All documents of the project can be divided into the following categories :
1. Data definition file :bookmarks.sql
It is used to establish the required database and data table .
2. Database connection file :db_fns.php
Used to connect to the database . Save the user name and password of the database user .
3. Input data validation file :user_auth_fns.php
Used to verify input data . test POST Whether the value of the variable is empty ,email Whether the input is legal .
4. User authentication file :user_auth_fns.php
Used to verify whether users can register 、 Sign in 、 Change Password 、 Reset password , And whether the user has logged in .
It is composed of several functions with corresponding functions , Function to receive parameters , Connect to the database for query , Return the query result or throw an exception .
5. Bookmark operation file :url_fns.php
For bookmarking url The query 、 increase 、 Delete and recommend . The function implementation method is similar to the previous one .
6. Browser output file :output_fns.php
Used to display all kinds of browser output :
Page name 、 In page title 、 Various forms 、 On page URL、 Website information 、 User menu 、 footer .
Each function implements the browser output of a kind of part , Functions can receive parameters as needed , stay HTML Insert php Show , It can also be done through php Output HTML Elements .
7. A file that contains a set of frequently referenced files :bookmark_fns.php
8.9. Form file and corresponding logic processing file
| Form file | login.php | change_passwd_form.php | register_form.php | forgot_form.php | add_bm_form.php |
|---|---|---|---|---|---|
| Logic processing files | member.php | change_passwd.php | register_new.php | forgot_passwd.php | add_bms.php |
Other logic processing files :
delete_bms.php、recommend.php
logout.php
Characteristics of form file :
1. Contains the bookmark_fns.php in output_fns.php References to functions in files ( That is, some browser output functions )
2. For forms that can only be filled out after login , Contains the session start function session_start() And verify whether the user has registered the session function check_valid_user().
Characteristics of logical processing files : Processing the data submitted by the form
1. Contains the bookmark_fns.php in output_fns.php References to functions in files ( That is, some browser output functions )
2. Contains the session start function session_start().
3. receive POST Variable information .
4. Whether the form is filled 、 Judge whether the input is legal .
5. Then call the user authentication function , If the verification passes , The relevant information will be displayed .
6. Catch all exceptions thrown , Reasonable display on the browser .
3. Key ideas of main modules
1. Database connection module :
Connect to database , return mysqli object .
function db_connect() {
$db = new mysqli('localhost', 'username', 'password', 'database');
if (!$db) {
throw new Exception("Could not connect to database server");
}else {
return $db;
}
}
2. Input data verification module :
// Verify that each variable has a value
function filled_out($form_vars) {
foreach ($form_vars as $key => $value) {
if ((!isset($key)) || ($value == '')) {
return false;
}
}
return true;
}
// test email
function valid_email($address) {
if(preg_match('/^[a-zA-Z0-9_\.\-][email protected][a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$/', $address)) {
return true;
} else {
return false;
}
}
3. User authentication module :
Connect to the database first , The query statement is then executed ( It is best to use parameterized query methods ), Return the corresponding value according to the query result .
function login($username, $password) {
$conn = db_connect();
$results = $conn -> query("select * from user where username = '".$username."' and passwd = sha1('".$password."')");
if (!$results) {
throw new Exception('Could not log you in.');
}
if ($results -> num_rows > 0) {
return true;
} else {
throw new Exception('Could not log you in.');
}
}
4. Login login module :
// Login successful , Set up session
$_SESSION['valid_user'] = $username;
// Log out , Save the user name first , Write off again , Give different prompts by judging whether the user name exists
$old_user = $_SESSION['valid_user'];
unset($_SESSION['valid_user']);
$result_dest = session_destroy();
if (!empty($old_user)) {
if ($result_dest) {
echo 'Logged out.<br />';
}else {
echo 'Could not log you out.<br />';
}
}else {
echo 'You are not logged in ,so have not been logged out.<br />';
}
5.url Recommended modules sql sentence :
If two users collect the same URL, Then maybe they have similar hobbies , You can put one user's favorite other URL Recommend to another user .
bookmark There are two columns in the data table ,bm_URL and username.
$query = "select bm_URL from bookmark where username in (select distinct(b2.username) from bookmark b1, bookmark b2 where b1.bm_URL = b2.bm_URL and b1.username != b2.username and b1.username = '".$valid_user."') and bm_URL not in (select bm_URL from bookmark where b1.username = '".$valid_user."') group by bm_URL having count(bm_URL)>".$popularity;
边栏推荐
- idea正则表达式替换(idea正则搜索)
- Can the variable name be in Chinese? Directly fooled people
- 华为ensp路由器静态路由(默认路由的下一跳地址)
- Business data analysis of CDA level1 knowledge point summary
- Experiment the Arduino code of NTP network timing alarm clock with esp32+tm1638
- 实现一个家庭安防与环境监测系统(二)
- Okaleido launched the fusion mining mode, which is the only way for Oka to verify the current output
- Working principle of Lora to 4G and gateway repeater
- redis集群的三种方式
- Basic theory of monocular depth estimation and paper learning summary
猜你喜欢

Mysql表的操作

Mongodb source code deployment and configuration

手把手教你申请SSL证书

The practice of depth estimation self-monitoring model monodepth2 in its own data set -- single card / multi card training, reasoning, onnx transformation and quantitative index evaluation

科隆新能源IPO被终止:拟募资6亿 先进制造与战新基金是股东

Word set paste to retain only text
![[directory blasting tool] information collection stage: robots.txt, Yujian, dirsearch, dirb, gobuster](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
[directory blasting tool] information collection stage: robots.txt, Yujian, dirsearch, dirb, gobuster

Okaleido launched the fusion mining mode, which is the only way for Oka to verify the current output

飞盘局有多快乐?2022年轻人新潮运动报告

Brush questions - Luogu -p1152 happy jump
随机推荐
~4.2 CCF 2021-12-1 sequence query
word设置粘贴仅保留文本
Brush questions - Luogu -p1146 coin flip
Realize a family security and environmental monitoring system (I)
Problems and extensions of the monocular depth estimation model featdepth in practice
[force buckle] 645. Wrong set
Easy entry natural language processing series 12 hidden Markov models
Alibaba mqtt IOT platform "cloud product circulation" practice - the two esp32 achieve remote interoperability through the IOT platform
轻松入门自然语言处理系列 12 隐马尔可夫模型
Typora无法打开提示安装新版本解决办法
Oka pass rights and interests analysis is the best choice to participate in okaleido ecological construction
What financial products can I invest with some money in my hand?
Okaleido生态核心权益OKA,尽在聚变Mining模式
Workplace "digital people" don't eat or sleep 007 work system, can you "roll" them?
@Classmethod decorator
MySQL 01: Source command
飞沃科技IPO过会:年营收11.3亿 湖南文旅与沅澧投资是股东
DNS resolution error during windows unbutu20 lts apt, WGet installation
Word set paste to retain only text
Realize a family security and environmental monitoring system (II)