How can .htaccess be used to restrict access to specific PHP files or directories for authentication purposes?
To restrict access to specific PHP files or directories for authentication purposes, you can use the .htaccess file to set up basic authentication. This involves creating a .htpasswd file with usernames and passwords, and then specifying in the .htaccess file which files or directories require authentication. Users will be prompted to enter a username and password before they can access the restricted files or directories.
AuthType Basic
AuthName "Restricted Area"
AuthUserFile /path/to/.htpasswd
Require valid-user
<Files "example.php">
Require valid-user
</Files>
<Directory "/path/to/directory">
Require valid-user
</Directory>