Home >Backend Development >PHP Tutorial >htaccess file sets password protection for site folders
The AuthType in the first line refers to the adopted Authentication method. Here we choose the general Basic authentication method. It should be noted that the password transmission process in Basic authentication method is not encrypted. The more secure method is Digest, but the Digest authentication method requires the support of the mod_auth_digest module. It is best before use. First check whether the server has enabled the module; the authentication name recorded in the AuthName in the second line will be displayed on the authentication inquiry box. If there are multiple authentications, the authentication name can make it clearer what user name and password to enter for the current authentication. , unfortunately the authentication name does not seem to support Chinese; on the third line, enter the authentication file path where the user password is stored.
After creating the file, we need to inject the username and password into this file, if you are using Linux or Unix class Operating system, you can use the htpasswd command. If you can log in to your server through SSH, then you can use htpasswd to manage the username and password in the .htpasswd file. If not, there are many online tools (such as http:/ /www.htaccesstools.com/htpasswd-generator/ or http://www.4webhelp.net/us/password.php) can help you generate passwords for use in .htpasswd files. Or generate with php
Finally, test it, create a new folder passwordprotected, upload the two files and test them together Put the file test.php into the folder and upload the folder to the server root folder. If you are on the local test server, enter the path of http://localhost/passwordprotected/test.php. Will a popup pop up at this time? What about the authentication inquiry box? Enter the corresponding account name and password to see the server configuration. If a 500 error occurs in the browser, it is most likely caused by incorrect AuthUserFile path settings. |