How can .htaccess files be utilized in PHP to secure specific directories and prevent repeated authentication prompts?
To secure specific directories and prevent repeated authentication prompts in PHP, you can utilize .htaccess files to set up basic authentication. This involves creating a .htpasswd file with encrypted usernames and passwords, and then configuring the .htaccess file to require authentication for specific directories. This way, users will only need to enter their credentials once to access the protected directories.
// .htaccess file content
AuthType Basic
AuthName "Restricted Area"
AuthUserFile /path/to/.htpasswd
Require valid-user