How to protect against direct access to images?

Viewed 47043

I would like to create a web site with many images. But I would like to protect against direct access to images, e.g. direct links to images without visiting the web site.

What is the preferred way to do this? And what are the alternatives with Pros and cons?

I have some ideas (I don't know if they are possible):

  • File permissions
  • PHP Sessions
  • Temporary file names or URLs
  • HTTP Redirection?

Maybe this isn't practiced on many web sites? E.g. I tried to access a private photo on Facebook without beeing logged in, but I could still visit the photo.

The platform will probably be a Ubuntu machine with NginX and PHP.

10 Answers

There are perfomance issues on above answers. My solution is to login system is follows.

You can rename the directory of images every hour / day etc.

images/2h4h4h4h4282hdj/182828.png to something like images/dhd777rhrje82883/182828.png

You can do this to complete system or to the specific user.

Apache

httpd.conf

<Directory "/var/www/html/img">
    AllowOverride None
    order deny,allow
    Options FollowSymLinks
</Directory>
Related