PHP + MYSQL member system development instance tutorial, mysql instance tutorial. PHP + MYSQL member system development example tutorial, mysql instance tutorial this article completed the complete PHP + MySQL member system function through a simple instance. Is a very practical application. PHP + MYSQL member system development instance tutorial, mysql instance tutorial
This article uses a simple example to complete the functions of the PHP + MySQL membership system. Is a very practical application. The specific implementation steps are as follows:
I. Principles of the membership system:
Login --> judge --> Keep status (Cookie or Session) --> verify status and permissions
II. security of the member system:
1. learn to use constants to improve md5 security
2. cookies/sessions use less plaintext information
3. Session security is higher than Cookie
4. use cookies/sessions to read information and add judgment information as much as possible.
5. the Cookie/Session content should be simplified
6. timely destroy cookies/sessions for error messages
III. database test, table user_list, and its fields
Uid m_id username password
1 admin 291760f98414679e3fd3f9051b19b6f7
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 at registration.
IV. configuration page m_config.php:
<? Php session_start (); // database connection $ conn = mysql_connect ('localhost', 'root', ''); mysql_select_db ('test', $ conn ); // define the constant define (ALL_ps, "test100"); // view the logon status and permission 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] smaller permissions, when the value is 1, the highest permission is return $ row;} else {echo "you are not authorized to view this page"; exit ();}} else {echo "this page can be viewed only after logon"; exit () ;}// set the logon timeout function user_mktime ($ onlinetime) {$ new_time = mktime (); echo $ new_time-$ onlinetime. "The page is not operated in seconds "."
"; If ($ new_time-$ onlinetime> '10') {// Set the timeout value to 10 seconds. test with echo" logon timeout, please log on again "; 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 (); // when logging on, forget the time echo "logon successful";} else {echo "incorrect user name or password "; session_destroy (); // Eliminate all sessions when the password is incorrect. }}?>
6. set the permission and timeout page m_zhuangtai.php:
<? Php include ("m_config.php"); $ arr = user_shell ($ _ SESSION [uid], $ _ SESSION [user_shell], 1 ); // set this page to access user_mktime ($ _ SESSION [times]) only when the permission is set to 1. // Determine whether the timeout is 10 seconds // echo $ _ SESSION [times]."
"; // The logon Time // echo mktime ()."
"; // Current date // echo $ arr [username]."
"; // Echo $ arr [uid]."
";?>
Content that can be viewed with permissions
VII. test results:
1. log on with sss and sssssss, and the prompt is: the user name or password is incorrect. View m_zhuangtai.php. the prompt is: this page can be viewed only after logon.
2. after logging on with admin, you can view the content on the m_zhuangtai.php page because the permission is 1.
3. after logging on with admin, because the permission is 1, you can view the content on the m_zhuangtai.php page, but refresh the page 10 seconds later. the prompt is: no operation on this page has timed out in seconds X, log on again.
4. after logging on with admin2 admin2, because the permission is 2, you cannot view the content on the m_zhuangtai.php page. the prompt is: you are not authorized to view the page.
I hope this example will be helpful for PHP program development.
Php + mysql development example tutorial code News System Code
If the original book does not contain a CD or something, you can contact the author to see if it can be provided to you. If it doesn't work, you can follow the content in the book to make a big difference. if you have any questions, please feel free to ask me.
Source code of the PHP + MySql development instance tutorial
There are many websites. do you need a framework?
In this article, we use a simple example to complete the functions of the PHP + MySQL membership system. Is a very practical application. Details...