PHP + MYSQL membership system login is the implementation code of permission judgment. Copy the code as follows :? Phperror_reporting (0); session_start (); database connection $ connmysql_connect (localhost, root,); mysql_select_db (chenkun, $ conn); mysql_quer
The code is as follows:
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:
The code is as follows:
// 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:
The 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 ();
}
}
?>
Denglu_link
Denglu_link.php page:
The 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
The http://www.bkjia.com/PHPjc/324418.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/324418.htmlTechArticle code is as follows :? Php error_reporting (0); session_start (); // database connection $ conn = mysql_connect ('localhost', 'root', ''); mysql_select_db ('chenkn ', $ conn); mysql_quer...