In this paper, a simple example of the complete PHP+MYSQL member system functions. is a very practical application. The specific implementation steps are as follows: first, the principle of membership System: Login--------------- Session less with clear text information 3, session security to be greater than Cookie4, use cookie/session read information as far as possible to increase the judgment information 5, cookie/session content to be streamlined 6, for the timely destruction of the error information cookie/ Session III, Database test, table User_list, and its field UID m_id username password 1 1 admin 291760f98414679e3f D3F9051B19B6F7 2 2 admin2 895785cfa5d8157f4d33c58ae0f55123password: MD5 (ADMINTEST100), MD5 (admin2test 100) The password is bound to the constant test100, and then encrypted into the database, this step can be set at the time of registration. Iv. Configuration page m_config.php:<?php session_start (); Database connection $conn =mysql_connect (' localhost ', ' root ', '); mysql_select_db (' Test ', $conn); Define constants define (ALL_PS, "test100"); View login status and Permissions 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] The lower the privilege, the higher the 1 o'clock permission return $row; }else{echo "You do not have enough permissions to view this page"; Exit (); }else{echo "Login to view this page"; Exit (); }}//Set login timeout function user_mktime ($onlinetime) {$new _time=mktime (); echo $new _time-$onlinetime. " Seconds did not manipulate the page "." <br> "; if ($new _time-$onlinetime > ' 10 ') {//Set timeout of 10 seconds, test with echo "Login timeout, please login again"; Exit (); Session_destroy (); }else{$_session[times]=mktime (); }?> Five, 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 ();//Get Login to forget the time of the echo "login Success"; }else{echo "User name or password errorError "; Session_destroy ()///Password error when removing all session}}?><form action= "" method= "POST" > Username: <input name= "username" type = "text"/><br/> user name: <input name= "password" type= "password"/><br/> Verification Code: <input name= "code" type = "code"/>5213<br/><br/> <input name= "Submit" type= "submit" value= "Login"/></form> vi. Set permissions and Timeout page m_zhuangtai.php:<?php include ("m_config.php"); $arr =user_shell ($_session[uid],$_session[user_shell],1);//Set the page to access User_mktime ($_session[times] only if the permission is 1 o'clock) ;//Determine if the timeout is 10 seconds//echo $_session[times]. " <br> ";//login at the time//echo mktime ()." <br> ";//Current date//echo $arr [username]." <br> "; echo $arr [uid]. " <br> "; ?> have permission to view the content of seven, test results: 1, log in with Sss,sssssss, prompt: The user name or password error. To view m_zhuangtai.php, Tip: You can log in to view the page. 2, with admin admin login, because the permission is 1, so you can view the contents of the m_zhuangtai.php page. 3, with the admin admin login, because the permission is 1, so you can view the contents of the m_zhuangtai.php page, but after 10 seconds and then refresh, prompt: X seconds did not operate the page login timeout, please re-login. 4, with admin2 admin2 login, because the permission is 2, so can not view the contents of the m_zhuangtai.php page, tip: You do not have enough permissions to view the page. I hope that the examples described in this article on everyone pHP program development has helped.
Php+mysql Member System Development Example Tutorial