Session_start (); Include ("mysql tutorial. class. php "); $ Db = new mysql ('localhost', 'root', '', 'flx', 'conn', 'gbk '); // To facilitate the test, a specific user is simply defined here. In actual operations, the user information is obtained 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 (); /* Determine if the number of errors exceeds the limit */ // For users with logon errors more than three times, if the current time minus the start time, is less than the specified value, it is not allowed Xu is logging on; If ($ username = user ){ // Here, you can try to log on three times, and write it below as 2 because the page refresh is not synchronized with the database connection, // That is to say, the information obtained here is the first time when the second error message is inserted into the database. The number of times has been more than once; If ($ row ['login _ times ']> 2 ){ $ Current = time (); $ Passed_time = $ current-$ row ['login _ date']; Echo '. $ passed_time.' second <br> '; // Set the time to 900 seconds. During this period, 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 on more than 3 times, so within the limited time, // You cannot log on to the system even if the password is entered correctly; If ($ pw = pw ){ Exit ('you have entered more than three wrong password attempts. Please log on to the system in 15 minutes! '); } // Of course, this prompt is also given if the password entered by this user is not the correct one; If ($ pw! = Pw ){ Exit ('you have entered more than three wrong password attempts. Please log on to the system in 15 minutes! '); } } Else { // The time limit has been reached. This user can log on. Before logging on, the user must set the time of the previous login. Cleared; $ Mod_content = "'login _ times '= 0, 'login _ date' = 0 "; $ Condition = "'id' = 1 "; $ Db-> update ('limit _ login', $ mod_content, $ condition ); } } } |