title: Restrict access to images on my website except through my own htmls
body: <p>On my website I store user pictures in a simple manner such as:
  "image/user_1.jpg".</p>
  
  <p>I don't want visitors to be able to view images on my server just by trying user_ids. (Ex: www.mydomain.com/images/user_2.jpg, www.mydomain.com/images/user_3.jpg, so on...)</p>
  
  <p>So far I have three solutions in mind:</p>
  
  <ol>
  <li><p>I tried using .htaccess to password protect the "images" folder. That helped me up to some point but some of the images started popping up a username and password request on my htmls (while amazingly some images did not) so this seems to be an unpredictable method.</p></li>
  <li><p>I can start converting my user_id's to an md5 hash with some salt. The images would be named as: /image/user_e4d909c290d0fb1ca068ffaddf22cbd0.jpg. I don't like this solution. It makes the file system way complicated.</p></li>
  <li><p>or I can user PHP's readfile() function or maybe something similar in Perl or Python. For instance I could pass a password using an md5 string to validate visitors as loggedin users with access to that image.</p></li>
  </ol>
  
  <p>I'm leaning towards option 3 but with a Perl or Python angle (assuming they would be faster than PHP). However I would like to see other ideas on the matter. Maybe there is a simple .htaccess trick to this? </p>
  
  <p>Basically all I want to make sure is that no one can view images from my website unless the images are directly called from within htmls hosted on my site.</p>
  
  <p>Thanks a lot,</p>
  
  <p>Haluk</p>