Copy Code code as follows:
<?php
error_reporting (0);
Session_Start ();
Database connection
$conn = mysql_connect (' localhost ', ' root ', ');
mysql_select_db (' Chenkun ', $conn);
mysql_query (' SET NAMES UTF-8 ');
Defining constants
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 lack of authority";
Exit ();
} else {
echo "You do not have access to the page";
Exit ();
}
}
function User_mktime ($onlinetime) {
$new _time = Mktime ();
if ($new _time-$onlinetime) > ' 900 ') {
Session_destroy ();
echo "Login Timeout";
Exit ();
} else {
$_session[' times '] = Mktime ();
}
}
?>
Php+mysql member System Landing is the right to judge
Contains three pages, Cogfig pages are included. Denglu page is responsible for submitting, session assignment and so on, Denglu_link page is responsible for the demonstration of authority judgment.
This example already exists in the test database, User_list table, the table has uid,m_id,username,password four fields. And the password field has been MD5 encrypted in the form of: MD5 (user password). ALL_PS), that is, the user entered the password plus constant encryption.
config.php page:
Copy Code code as follows:
<?php
Start session
Session_Start ();
Database connection
$conn =mysql_connect (' localhost ', ' root ', ' Hu Jintao ');
mysql_select_db (' Test ', $conn);
Defining constants
Define ("All_ps", "php100");
Judging permission functions
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));
$exist 2= $exist $shell ==md5 ($row [' username ']. $row [' Password ']. ALL_PS): FALSE;
if ($exist 2) {
return $row;
}else{
echo "You do not have access to the page";
Exit ();
}
}
?>
denglu.php page:
Copy Code code 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)); To determine if there is such a user
$exist 2= $exist MD5 ($_post[' password '). ALL_PS) = = $row [' Password ']:false;//judgment password
if ($exist 2) {
$_session[' uid ']= $row [' uid ']; Session Assignment
$_session[' User_shell ']=md5 ($row [' username ']. $row [' Password ']. ALL_PS);
echo "landed success";
}else{
echo "Incorrect user name";
Session_destroy ();
}
}
?>
<form action= "" method= "POST" >
User name: <input type= "text" name= "username"/><br>
Password: <input type= "password" name= "password"/><br>
Verification code: <input type= "code" name= "code" size= "Ten"/>
<br><br>
<input type= "Submit" name= "Submit" value= "Landing"/>
</form>
<a href= "http://127.0.0.1/test/denglu_link.php" >denglu_link</a>
denglu_link.php page:
Copy Code code as follows:
?
Include ("config.php");
$arr =user_shell ($_session[' uid '],$_session[' User_shell ']);//The above two sentences can judge the authority
echo $arr [' username '];
?>
Permission content