Copy codeThe Code is as follows: <? Php
Error_reporting (0 );
Session_start ();
// Database connection
$ Conn = mysql_connect ('localhost', 'root ','');
Mysql_select_db ('chenkn', $ conn );
Mysql_query ('set NAMES UTF-8 ');
// Define a constant
Define ('all _ Ps', 'php ');
Function user_shell ($ uid, $ shell, $ m_id ){
$ SQL = "select * from admin where uid = '$ uid '";
$ Query = mysql_query ($ SQL );
$ Row = mysql_fetch_array ($ query );
$ Shell = is_array ($ row )? $ Shell = md5 ($ row ['username']. $ row ['Password']. ALL_PS): FALSE;
If ($ shell ){
If ($ row ['m _ id'] <= $ m_id ){
Return $ row;
}
Echo "your permissions are insufficient ";
Exit ();
} Else {
Echo "You are not authorized to access this page ";
Exit ();
}
}
Function user_mktime ($ onlinetime ){
$ New_time = mktime ();
If ($ new_time-$ onlinetime)> '20140901 '){
Session_destroy ();
Echo "Login timeout ";
Exit ();
} Else {
$ _ SESSION ['times '] = mktime ();
}
}
?>
Logon to the PHP + MYSQL membership system is a permission judgment
Contains three pages. cogfig pages are contained pages. The denglu page is responsible for submission and session assignment, and the denglu_link page is responsible for demonstration of permission judgment.
In this example, the test database and user_list table already exist. The table has four fields: uid, m_id, username, and password. The password field has been encrypted by md5 in the form of md5 ("User password". ALL_PS), that is, the password entered by the user is encrypted by a constant.
Config. php page:Copy codeThe Code is as follows: <? Php
// Start the session
Session_start ();
// Database connection
$ Conn = mysql_connect ('localhost', 'root ','******');
Mysql_select_db ('test', $ conn );
// Define a constant
Define ("ALL_PS", "php100 ");
// Permission judgment Function
Function user_shell ($ uid, $ shell ){
$ SQL = "SELECT * FROM 'user _ list' WHERE 'uid' = '$ uid '";
$ Query = mysql_query ($ SQL );
$ Exist = is_array ($ row = mysql_fetch_array ($ query ));
$ Exist2 = $ exist? $ Shell = md5 ($ row ['username']. $ row ['Password']. ALL_PS): FALSE;
If ($ exist2 ){
Return $ row;
} Else {
Echo "You are not authorized to access this page ";
Exit ();
}
}
?>
Denglu. php page:Copy codeThe Code is as follows: <?
Include ("config. php ");
If ($ _ POST ['submit ']) {
$ Username = str_replace ("", "", $ _ POST ['username']); // remove Spaces
$ SQL = "SELECT * FROM 'user _ list' WHERE 'username' = '$ username '";
$ Query = mysql_query ($ SQL );
$ Exist = is_array ($ row = mysql_fetch_array ($ query); // you can check whether such a user exists.
$ Exist2 = $ exist? Md5 ($ _ POST ['Password']. ALL_PS) = $ row ['Password']: FALSE; // determine the password
If ($ exist2 ){
$ _ SESSION ['uid'] = $ row ['uid']; // session value assignment
$ _ SESSION ['user _ shell'] = md5 ($ row ['username']. $ row ['Password']. ALL_PS );
Echo "Login successful ";
} Else {
Echo "incorrect user name ";
SESSION_DESTROY ();
}
}
?>
<Form action = "" method = "post">
Username: <input type = "text" name = "username"/> <br>
Password: <input type = "password" name = "password"/> <br>
Verification code: <input type = "code" name = "code" size = "10"/>
<br>
<Input type = "submit" name = "submit" value = "login"/>
</Form>
<A href = "http: // 127.0.0.1/test/denglu_link.php"> denglu_link </a>
Denglu_link.php page:Copy codeThe Code is as follows: <?
Include ("config. php ");
$ Arr = user_shell ($ _ SESSION ['uid'], $ _ SESSION ['user _ shell']); // you can determine the permissions in the preceding two statements.
Echo $ arr ['username'];
?>
Permission content