Copy CodeThe code is as follows:
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 "You have insufficient authority";
Exit ();
} else {
echo "You have no access to this 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 login is the right to judge
Contains three pages, the Cogfig page is the included page. Denglu page is responsible for submitting, session assignment, etc., Denglu_link page is responsible for the demonstration of authority judgment.
In this case, the test database already exists, the User_list table, and the table has a uid,m_id,username,password of four fields. And the password field has been MD5 encrypted in the form: MD5 ("User password"). ALL_PS), which is the password and constant entered by the user to encrypt.
config.php page:
Copy CodeThe code is as follows:
Start session
Session_Start ();
Database connection
$conn =mysql_connect (' localhost ', ' root ', ' ****** ');
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 have no access to 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)); Determine if such a user exists
$exist 2= $exist? MD5 ($_post[' password '). ALL_PS) = = $row [' Password ']:false;//to determine the password
if ($exist 2) {
$_session[' uid ']= $row [' uid ']; Session Assignment
$_session[' User_shell ']=md5 ($row [' username ']. $row [' Password ']. ALL_PS);
echo "Landing success";
}else{
echo "Incorrect user name";
Session_destroy ();
}
}
?>
Denglu_link
denglu_link.php page:
Copy CodeThe code is as follows:
Include ("config.php");
$arr =user_shell ($_session[' uid '],$_session[' User_shell ');//the permission can be judged by the above two sentences
echo $arr [' username '];
?>
Permission content
http://www.bkjia.com/PHPjc/324418.html www.bkjia.com true http://www.bkjia.com/PHPjc/324418.html techarticle Copy the code as follows: PHP error_reporting (0); session_start ();//database connection $conn = mysql_connect (' localhost ', ' root ', '); mysql_se lect_db (' Chenkun ', $conn); Mysql_quer ...