


PHP+MYSQL membership system development example tutorial, mysql example tutorial_PHP tutorial
PHP+MYSQL membership system development example tutorial, mysql example tutorial
This article completes the complete PHP+MySQL membership system function through a simple example. It is a very practical application. The specific implementation steps are as follows:
1. Principle of membership system:
Login-->Judgment-->Keep status (Cookie or Session)-->Verify status and permissions
2. Security of membership system:
1. Learn to use constants to improve md5 security
2. Cookie/Session use less plain text information
3. Session security is greater than Cookie
4. Use Cookie/Session to read information and try to increase the judgment information
5. Cookie/Session content should be streamlined
6. Destroy Cookie/Session in time for error messages
3. Database test, table user_list, and its fields
uid m_id username password
1 1 1 admin 291760f98414679e3fd3f9051b19b6f7
2 2 2 admin2 895785cfa5d8157f4d33c58ae0f55123
Password: md5 (admintest100) and md5 (admin2test100) respectively. That is, the password is bound to the constant test100 and then encrypted and stored in the database. This step can be set during registration.
4. Configuration page m_config.php:
<?php session_start(); //数据库连接 $conn=mysql_connect('localhost','root',''); mysql_select_db('test',$conn); //定义常量 define(ALL_ps,"test100"); //查看登录状态与权限 function user_shell($uid,$shell,$m_id){ $sql="select * from user_list where `uid`='$uid'"; $query=mysql_query($sql); $us=is_array($row=mysql_fetch_array($query)); $shell=$us ? $shell==md5($row[username].$row[password].ALL_PS):FALSE; if($shell){ if($row[m_id]<=$m_id){//$row[m_id]越小权限越高,为1时权限最高 return $row; }else{ echo "你的权限不足,不能查看该页面"; exit(); } }else{ echo "登录后才能查看该页"; exit(); } } //设置登录超时 function user_mktime($onlinetime){ $new_time=mktime(); echo $new_time-$onlinetime."秒未操作该页面"."<br>"; if($new_time-$onlinetime>'10'){//设置超时时间为10秒,测试用 echo "登录超时,请重新登录"; exit(); session_destroy(); }else{ $_SESSION[times]=mktime(); } } ?>
5. Login page m_user.php:
<?php include("m_config.php"); //echo md5("admin2".ALL_PS); if($_POST[submit]){ $username=str_replace(" ","","$_POST[username]"); $sql="select * from user_list where `username`='$username'"; $query=mysql_query($sql); $us=is_array($row=mysql_fetch_array($query)); $ps=$us ? md5($_POST[password].ALL_PS)==$row[password] : FALSE; if($ps){ $_SESSION[uid]=$row[uid]; $_SESSION[user_shell]=md5($row[username].$row[password].ALL_PS); $_SESSION[times]=mktime();//取得登录时忘该的时间 echo "登录成功"; }else{ echo "用户名或密码错误"; session_destroy();//密码错误时消除所有的session } } ?> <form action="" method="post"> 用户名:<input name="username" type="text" /><br /> 用户名:<input name="password" type="password" /><br /> 验证码:<input name="code" type="code" />5213<br /><br /> <input name="submit" type="submit" value="登录" /> </form>
6. Page m_zhuangtai.php with permissions and timeout set:
<?php include("m_config.php"); $arr=user_shell($_SESSION[uid],$_SESSION[user_shell],1);//设置该页面只有权限为1时即最高权限的才能访问 user_mktime($_SESSION[times]);//判断是否超时10秒 //echo $_SESSION[times]."<br>";//登录时该的时间 //echo mktime()."<br>";//当前日期 //echo $arr[username]."<br>"; //echo $arr[uid]."<br>"; ?>
Content that can only be viewed with permission
7. Test results:
1. Log in with sss, sssssss, prompt: wrong username or password. View m_zhuangtai.php, prompt: You must log in to view this page.
2. After logging in with admin admin, because the permission is 1, you can view the content of the m_zhuangtai.php page.
3. After logging in with admin admin, because the permission is 1, you can view the content of the m_zhuangtai.php page, but if you refresh it after 10 seconds, it will prompt: The page has not been operated for X seconds. The login has timed out, please log in again.
4. After logging in with admin2 admin2, because the permission is 2, the content of the m_zhuangtai.php page cannot be viewed. Tip: You have insufficient permissions and cannot view the page.
I hope the examples described in this article will be helpful to everyone in PHP program development.
The original book does not come with a CD or something. You may consider contacting the author and asking if he can give it to you. If it really doesn't work, you can follow the content in the book and you will gain a lot. If you have any questions, you can ask me at any time.
There are many online, do you need a framework?

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











MySQL and phpMyAdmin can be effectively managed through the following steps: 1. Create and delete database: Just click in phpMyAdmin to complete. 2. Manage tables: You can create tables, modify structures, and add indexes. 3. Data operation: Supports inserting, updating, deleting data and executing SQL queries. 4. Import and export data: Supports SQL, CSV, XML and other formats. 5. Optimization and monitoring: Use the OPTIMIZETABLE command to optimize tables and use query analyzers and monitoring tools to solve performance problems.

AI can help optimize the use of Composer. Specific methods include: 1. Dependency management optimization: AI analyzes dependencies, recommends the best version combination, and reduces conflicts. 2. Automated code generation: AI generates composer.json files that conform to best practices. 3. Improve code quality: AI detects potential problems, provides optimization suggestions, and improves code quality. These methods are implemented through machine learning and natural language processing technologies to help developers improve efficiency and code quality.

session_start()iscrucialinPHPformanagingusersessions.1)Itinitiatesanewsessionifnoneexists,2)resumesanexistingsession,and3)setsasessioncookieforcontinuityacrossrequests,enablingapplicationslikeuserauthenticationandpersonalizedcontent.

In MySQL, add fields using ALTERTABLEtable_nameADDCOLUMNnew_columnVARCHAR(255)AFTERexisting_column, delete fields using ALTERTABLEtable_nameDROPCOLUMNcolumn_to_drop. When adding fields, you need to specify a location to optimize query performance and data structure; before deleting fields, you need to confirm that the operation is irreversible; modifying table structure using online DDL, backup data, test environment, and low-load time periods is performance optimization and best practice.

To safely and thoroughly uninstall MySQL and clean all residual files, follow the following steps: 1. Stop MySQL service; 2. Uninstall MySQL packages; 3. Clean configuration files and data directories; 4. Verify that the uninstallation is thorough.

Efficient methods for batch inserting data in MySQL include: 1. Using INSERTINTO...VALUES syntax, 2. Using LOADDATAINFILE command, 3. Using transaction processing, 4. Adjust batch size, 5. Disable indexing, 6. Using INSERTIGNORE or INSERT...ONDUPLICATEKEYUPDATE, these methods can significantly improve database operation efficiency.

MySQL functions can be used for data processing and calculation. 1. Basic usage includes string processing, date calculation and mathematical operations. 2. Advanced usage involves combining multiple functions to implement complex operations. 3. Performance optimization requires avoiding the use of functions in the WHERE clause and using GROUPBY and temporary tables.

Composer is a dependency management tool for PHP, and manages project dependencies through composer.json file. 1) parse composer.json to obtain dependency information; 2) parse dependencies to form a dependency tree; 3) download and install dependencies from Packagist to the vendor directory; 4) generate composer.lock file to lock the dependency version to ensure team consistency and project maintainability.
