This article shares a simple PHP user login code that detects if the user name and password are compared to the values stored in the array. A friend in need can make a reference. First, the user name and password are stored in the array, and when a user logs in, the value from the array participates in detection to determine whether the user name and password are valid. Log in and detect in the same file Loginformaction, code:
2, the following code, through a custom PHP function, to implement user login detection. You can detect the user name and password length, whether the user name and password are correct. Code:
0) {if (!isset ($p [' username ']) | | (Trim ($p [' username ']) = = ")) {$errors [] = ' You must enter a username. '; }elseif{((strlen ($p [' username ']) < 8) | | (Ereg (' [^a-za-z0-9] ', $p [' username ']))) {$errors [] = ' username is invalid, enter a user name of at least 8 digits and only contain a combination of letters and numbers. '; } if (!isset ($p [' Password ']) | | (Trim ($p [' password ']) = = ")) {$errors [] = ' You must enter a password. '; }elseif ((strlen ($p [' Password ']) < 8) | | (Ereg (' [^[:alnum:][:p unct:][:space:]] ', $p [' Password '])) {$errors [] = ' Password is invalid, enter a password of at least 8 digits and only include letters, numbers, punctuation, and spaces. '; } if (count ($errors) = = 0) {$r = Validate_user ($p [' username '], $p [' Password ']); if ($r = = False) {$errors [] = ' Login failed, user name and password error. '; } else {print ('<title>Login successful</title> Congratulations on your Login successfully! '); Exit }}}?><title>User Login</title>User Login
0) {$n = count ($errors); for ($i = 0; $i < $n; $i + +) {print ' ' . $errors [$i]. ''; }}?> |