Php user logon code (cookie, database) _ PHP Tutorial

Source: Internet
Author: User
Php user logon code (cookie, database ). Below we will talk about two types of user logon methods. one is to use window verification and database tutorial password verification to achieve login. The latter is to use cookies to record user information for login, the following describes two methods for user logon. one is to use window verification and database tutorial password verification to log on. The other is to use cookies to record user information, if you need it, try it.

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, pstutorial wd FROM user WHERE username = '$ _ SERVER [PHP_AUTH_USER]' AND pswd = MD5 ('$ _ SERVER [PHP_AUTH_PW]')";

$ Result = mysql_query ($ query );

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

Use cookie to log on



Enter Password









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.