I have a folder named - Images. This folder contains user profile pictures. Right now a user can see his image by just copying the image URL to his browser any time. This way he can also see other user's profile pics. What I want to achieve is - The user should be able to see his profile pic only through the PHP page on my website. If the user directly puts the image URL, it should not be displayed.
I tried to achieve this using .htaccess. This is what I have in the .htaccess file :
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mysite.com/
RewriteRule \.(gif|jpg)$ http://www.mysite.com/errorpost.jpg [R,L]
I am new to .htaccess. If there is a way to achieve this, please help.
Thanks in advance.
I have the same problem. Currently I found 2 ways:
1) base64_encode() + ajax + js/jquery
pros
cons
2) long-random-names (+symlinks)
A) Store images in www folder using long-random names
B) Store images outside www folder with symlinks to www folder. (images outside www can also work as your desktop images backup)
notes:
example of image hierarchy:
pros:
cons
=====================================
I had implemented case 1) and it worked for me fine, however I did not found similar solution for HTML5 video.
Case 2) seems more flexible. However I still not sure about security. If anyone sees security holes please let me know.