- AuthType Basic
- AuthName "restricted area"
- AuthUserFile/full/path/to/passwordprotected/. htpasswd
- Require valid-user
The AuthType in the first line refers to the authentication method used. Here we select general Basic. Note that the password transmission process in Basic authentication mode is not encrypted, the safer method is Digest, but the Digest Authentication method requires the support of the mod_auth_digest module. before using it, it is best to check whether the module has been enabled on the server; the authentication name recorded by the AuthName in the second line, it will be displayed in the authentication inquiry box. if there are multiple authentication, the authentication name will help you better understand the username and password for the current authentication. Unfortunately, the authentication name does not seem to support Chinese characters; line 3: enter the path of the authentication file that stores the user password.
- Username: 123456
- Username: 654321
- Users: 12tio. zIbWQ3c
After creating the file, we need to inject the user name and password to the file. if you use a Linux or Unix operating system, you can run the htpasswd command, if you can log on to your server through SSH, you can use htpasswd for management. user name and password in the htpasswd file, if not, there are a lot of online tools (such as http://www.htaccesstools.com/htpasswd-generator/ or http://www.4webhelp.net/us/password.php) can help you generate. the password used in the htpasswd file. Or use php to generate
- // Password to be encrypted for a. htpasswd file
- $ ClearTextPassword = 'some password ';
- // Encrypt password
- $ Password = crypt ($ clearTextPassword, base64_encode ($ clearTextPassword ));
- // Print encrypted password
- Echo $ password;
Finally, test it. create a folder named passwordprotected to upload the two files and test the same test file. put php in this folder and upload the folder to the root folder of the server. if you are on the local test server, enter http: // localhost/passwordprotected/test. php path. will an authentication inquiry box pop up?
Enter the account name and password to view the server configuration. If a 500 error occurs in the browser, it is likely that the AuthUserFile path is incorrectly set.