PHP User authentication PHP database-based user authentication code

Source: Internet
Author: User
Tags php database
share a PHP user-authenticated code, Based on the information stored in the database for user authentication, there is a need for friends to refer to it.

PHP Implementation of user authentication of an example code, we refer to the next.

Code:

!--? php/*** database-based Browser authentication * edit by bbs.it-home.org*/funct      Ion Authenticate_user () {header (' Www-authenticate:basic realm= ' Secret Stash "');      Header ("http/1.0 401 Unauthorized");   Exit   } if (! isset ($_server[' Php_auth_user '))) {Authenticate_user ();      } else {mysql_pconnect ("localhost", "authenticator", "secret") or Die ("failed to connect to database server!");      mysql_select_db ("Java2s") or Die ("failed to connect to database!"); $query = "Select Username, pswd from user WHERE username= ' $_server[php_auth_user] ' and pswd=md5 (' $_server[php_au      TH_PW] ";      $result = mysql_query ($query);      If nothing is found, continue to display the password input prompt if (mysql_num_rows ($result) = = 0) {authenticate_user (); }   }?-->
  • 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.