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...