0

I develop a web site, but I have a problem in images,

for more explain : I insert the pictures in a folder and call them with the URL

for example the folder name is : images

And I insert a picture with name : test.jpg

So, the problem is if someone know the name of picture, he can be seen it, www.testest.com/images/test.jpg, but I need to block the pictures

If someone has other solution, Do not spare me the solution, because I want to give some privacy to the user

So, what the perfect solution to destroy this problem, I try a lot to found and fix it but without any result.

Any help please ?

saadsaad
  • 35
  • 12

2 Answers2

2

Without knowing the full details of how you're actually using these images:

  1. Store the images outside of the root directory, in a folder that is not web accessible.
  2. Create a script to fetch the images (ie, images.php?id=123). This will present the same problem you currently face, if someone knows the ID, so moving on...
  3. Implement whatever logic you need to prevent these images from being loaded by unwanted sources, for example if the user is not logged in or it's being requested by an external website / leached.

You can't really get more secure than that, outside of not having any images at all.

mister martin
  • 6,197
  • 4
  • 30
  • 63
  • 1
    If `images.php` checks that the connection is logged in using Session etc this would be even more secure, but would not stop a logged in user from looking around to see what they could find – RiggsFolly Nov 22 '16 at 14:12
  • 1
    @RiggsFolly the images could be restricted to that particular user / session. without more details, we can only guess what logic is actually needed. – mister martin Nov 22 '16 at 14:21
  • Yup I realise this is a bit of a guessing game based on the info provided. I was just trying to add a little to your answer which was what I was going to write – RiggsFolly Nov 22 '16 at 14:23
  • @mistermartin I think is like facebook ? because it use a file named `images.php?id=123` but if I make pictures in a file is not web accessible he can't make problems ? – saadsaad Nov 22 '16 at 18:06
  • @saadsaad see [this answer](http://stackoverflow.com/questions/1851849/output-an-image-in-php) – mister martin Nov 22 '16 at 18:12
0

1- Prevent hotlink with htaccess:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yourdomain.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ www.testest.com/images/ [NC,R,L]

2- Disable right-click for all the <img>:

JQUERY:

$('img').bind('contextmenu', function(e) {
    return false;
}); 

CSS:

img{
  -webkit-user-select: none;  /* Chrome all / Safari all */
  -moz-user-select: none;     /* Firefox all */
  -ms-user-select: none;      /* IE 10+ */
  -o-user-select: none;
  user-select: none;
}
paolobasso
  • 2,008
  • 12
  • 25