Two types of PHP user login codes (cookies, databases) _php tutorials

Source: Internet
Author: User
Tags mysql tutorial setcookie
Below we want to talk about two kinds of user login methods one is to use the window authentication and database tutorial password Authentication to achieve login, the latter is the use of cookie logging user information to log in, the need for friends can try.

function 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 tutorial _pconnect ("localhost", "authenticator", "secret") or Die ("Can ' t connect to Database server!");
mysql_select_db ("Java2s") or Die ("Can ' t select Authentication database!");

$query = "Select Username, PS Tutorial wd from user WHERE username= ' $_server[php_auth_user] ' and PSWD=MD5 (' $_SERVER[PHP_AUTH_PW] ')";

$result = mysql_query ($query);

If Nothing is found, reprompt the user for the login www.zhutiai.com information.
if (mysql_num_rows ($result) = = 0) {
Authenticate_user ();
}
}
?>

Using the cookie Login method



<title>Enter Password</title>









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.