PhpapachePHP_AUTH_USER logon method_php tutorial

Source: Internet
Author: User
PhpapachePHP_AUTH_USER logon method. The HTTP authentication mechanism of PHP is only valid when PHP runs in the Apache module mode. Therefore, this function is not applicable to CGI versions. In the PHP script of the Apache module, the HTTP authentication mechanism of the header () function PHP can be used only when PHP runs in the Apache module mode. Therefore, this function is not applicable to CGI versions. In the PHP script of the Apache module, you can use the header () function to send the "Authentication Required" message to the client browser to bring up a user name/password input window. After the user enters the user name and password, the PHP script containing the URL will be called again with the predefined variables PHP_AUTH_USER, PHP_AUTH_PW, and AUTH_TYPE. these three variables are set as user names respectively, password and authentication type. The predefined variables are stored in the $ _ SERVER or $ HTTP_SERVER_VARS array. The system only supports "basic" authentication

$ Authorized = FALSE;

If (isset ($ _ SERVER ['php _ AUTH_USER ']) & isset ($ _ SERVER ['php _ AUTH_PW']) {
$ AuthFile = file ("./password.txt ");

Foreach ($ authFile as $ login ){
List ($ username, $ password) = explode (":", $ login );
$ Password = trim ($ password );
If ($ username = $ _ SERVER ['php _ AUTH_USER ']) & ($ password = md5 ($ _ SERVER ['php _ AUTH_PW']) {
$ Authorized = TRUE;
Break;
}
}
}

// If not authorized, display authentication prompt or 401 error
If (! $ Authorized ){
Header ('www-Authenticate: Basic Realm = "Secret Stash "');
Header ('http/1.0 401 unauthorized ');
Print ('you must provide the proper credentials! ');
Exit;
}

?>


The HTTP authentication mechanism for http://www.bkjia.com/PHPjc/629712.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/629712.htmlTechArticlePHP is only valid when PHP runs as an Apache module, so this function is not applicable to CGI versions. In the PHP script of the Apache module, you can use the header () function...

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.