Code Sample for PHP user login detection

Source: Internet
Author: User
Tags ereg setcookie
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]. ''; }}?>
  • Related Article

    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.