What role does .htaccess play in preventing image theft using PHP?
To prevent image theft using PHP, you can use .htaccess to restrict access to the image files from being directly accessed by unauthorized users. By setting up rules in the .htaccess file, you can prevent hotlinking or direct linking to your images from external websites, thus reducing the chances of image theft.
# Prevent hotlinking of images
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yourwebsite.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F]
Keywords
Related Questions
- What are the best practices for handling SQL syntax errors in PHP, especially when querying databases with user input?
- How can a PHP beginner effectively utilize the PHP manual and other resources to troubleshoot and resolve database connection issues?
- Why is it recommended to use POST instead of GET for data modification?