PHP User Login code (limit the number of user error login) (_php) tutorial

Source: Internet
Author: User
Tags mysql tutorial
PHP User Login code (limit the number of user error login)

PHP Tutorial User Login code (limit number of user error login)

Session_Start ();
Include ("MySQL tutorial. class.php");
$db =new mysql (' localhost ', ' root ', ' ', ' FLX ', ' conn ', ' GBK ');
For the convenience of testing, here is just a simple definition of a specific user, in the actual operation, the user information from the database tutorial;
Define (' user ', ' admin ');
Define (' PW ', 123);
$db->findall (' Limit_login ');
$row = $db->fetch_array ();
Print_r ($row);
if ($_post[' submit ']) {
$username =$_post["username"];
$PW =$_post["PW"];
$_session[' time ']=time ();
/* ERROR number overrun judgment */
For users who have logged errors more than three times, if the current time, minus the time to start landing, less than a specific value, forbid
Xu in the landing;
if ($username ==user) {
Here users can try to login 3 times, the following is written as 2, is because the page refresh and database connection is not synchronized,
That is, the second error message is inserted into the database, the information obtained here, or the first time, the actual user error
The number of times has been more than once;
if ($row [' login_times ']>2) {
$current =time ();
$passed _time= $current-$row [' login_date '];
Echo ' is past now '. $passed _time ' s
';
Set time 900 seconds, during which a specific user cannot log on to the system;
if (($current-$row [' login_date ']) {<900) {
$test _PW=SUBSTR (MD5 (rand ()), 0,10);
Now the admin (specific user) user has logged in error more than 3 times, that within the limited time,
Even if his password is entered correctly, it cannot be logged into the system;
if ($PW ==pw) {
Exit (' Your password has been incorrectly entered more than three times, please login to the system in 15 minutes! ');
}
Of course, the user entered the password is not the correct password, but also give such a hint;
if ($PW!=pw) {
Exit (' Your password has been incorrectly entered more than three times, please login to the system in 15 minutes! ');
}
}else{
At this time, the user can log in, and before the user logs in, the time of the previous login
Qing 0;
$mod _content= "' Login_times ' =0, ' login_date ' = 0";
$condition = "' id ' = 1";
$db->update (' Limit_login ', $mod _content, $condition);
}
}
}

/* User Login Operation */

if ($username && $pw) {
if ($username ==user&& $pw ==pw) {
/* User Login successful, */
Update data table, table login times and time, all set 0;
$mod _content= "' Login_times ' =0, ' login_date ' = 0";
$condition = "' id ' = 1";
$db->update (' Limit_login ', $mod _content, $condition);
Echo ';
}else{
In the first error, set the password error number is 1, the login is the session saved time into the database;
if ($row [' Login_times ']==0&& $row [' login_date ']==0] {
$mod _content= "' Login_times ' =1, ' login_date ' = '". $_session[' time '. "'";
$condition = "' id ' = 1";
$db->update (' Limit_login ', $mod _content, $condition);
}else{
$mod _content= "' login_times ' = ' login_times ' +1";
$condition = "' id ' = 1";
$db->update (' Limit_login ', $mod _content, $condition);
}
/* Prompt the user for a few more opportunities */
if ($row [' login_times ']<3) {
$row [' Login_times ']++;//here the number of landings plus 1, and the above-mentioned reason, is because the connection can not be synchronized
database;
echo ' Password Error! The number of errors is: '. $row [' login_times ']. ' Times
';
$remain _times=3-$row [' login_times '];
Echo ' You still have '. $remain _times. ' Landing opportunities ';
}
}
}else{
echo ' username and password cannot be empty! ';
}
}



?>

1 2

http://www.bkjia.com/PHPjc/444885.html www.bkjia.com true http://www.bkjia.com/PHPjc/444885.html techarticle PHP User Login code (limit user error login) PHP Tutorial User login code (limit user error login) session_start (); include (MySQL tutorial. class.php); $db =new my ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.