User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Site Layout and Usability section within the Web Development category of DaniWeb, a massive community of 401,641 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,781 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Views: 836 | Replies: 5
Reply
Join Date: Jun 2007
Posts: 17
Reputation: ghostsquad is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
ghostsquad ghostsquad is offline Offline
Newbie Poster

Solution blocking direct image access

  #1  
Dec 17th, 2007
So, I've scoured the web for a way to block direct access to an image, kind of like hotlinking, but on my website.

For example: going to http://www.mydomain.com/images/someimage.gif should bring the user to a 403 (access denied) page instead of displaying the image. I wanted to do this using .htaccess and for all to know, this is how I did it.

I can use phpThumb (http://phpthumb.sourceforge.net/) to display thumbnails, but someone can also use this to simply "parse" the image, without modifying it in any way (displayed below)

Here's how the .htaccess looks

# normal hotlink prevention requires first 3 lines (3rd line being for my localserver)
# using phpThumb to display my images allows the images to be displayed on the website
# but when tried to access directly ie. http://www.mydomain.com/images/foo.gif
# the user is redirected to error 403 page
# which means I don't need to have those conditions. Infact, with those conditions in place allows users
# to see the images (but still cannot hotlink)

#RewriteCond %{HTTP_REFERER} !^$
#RewriteCond %{HTTP_REFERER} !^http://(www.)?mydomain.com/.*$ [NC]
#RewriteCond %{HTTP_REFERER} !^http://(www.)?mydomain.dev/.*$ [NC]
RewriteRule \.(gif|jpe?g|png)$ - [F,NC]

All images are written in this format on my website:

<img src="lib/php/functions/phpThumb/phpThumb.php?src=/lib/images/foo.gif" alt="foo" />

if anyone has any better way to do this, I would gladly appreciate knowing. This is just something I found out on accident actually.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2007
Posts: 75
Reputation: hielo is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 10
hielo hielo is offline Offline
Junior Poster in Training

Re: blocking direct image access

  #2  
Dec 19th, 2007
Reply With Quote  
Join Date: Jan 2007
Posts: 2,537
Reputation: MidiMagic is on a distinguished road 
Rep Power: 7
Solved Threads: 108
MidiMagic's Avatar
MidiMagic MidiMagic is offline Offline
Posting Maven

Re: blocking direct image access

  #3  
Dec 20th, 2007
Why do you want to hide images? If you don't want people to see your images, don't put them on the Internet.

You aren't going to stop people from copying your images either. Anyone can do a Ctrl-Print-Screen and recover the image in MS Paint.
Daylight-saving time uses more gasoline
Reply With Quote  
Join Date: Jun 2007
Posts: 17
Reputation: ghostsquad is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
ghostsquad ghostsquad is offline Offline
Newbie Poster

Re: blocking direct image access

  #4  
Dec 20th, 2007
Originally Posted by MidiMagic View Post
Why do you want to hide images? If you don't want people to see your images, don't put them on the Internet.

You aren't going to stop people from copying your images either. Anyone can do a Ctrl-Print-Screen and recover the image in MS Paint.

The images on the website get watermarked and resized dynamically using phpThumb. Infact, phpThumb can do lots to images. I want to make the image once in Photoshop, and use phpThumb to do the rest. For security reasons, I don't want web users to be able to get to, and use the unformatted images.
Reply With Quote  
Join Date: Jan 2007
Posts: 2,537
Reputation: MidiMagic is on a distinguished road 
Rep Power: 7
Solved Threads: 108
MidiMagic's Avatar
MidiMagic MidiMagic is offline Offline
Posting Maven

Re: blocking direct image access

  #5  
Dec 22nd, 2007
Security??? I think of security as keeping people from breaking into a computer and doing damage, or keeping them from stealing Social Insecurity numbers. I don't think of someone downloading an image from your page as a security issue, but a copyright infringement.

Something tells me that copyright will disappear in ten years or less, because the Internet will make it cost-prohibitive to enforce.

For your "security" reasons, you should store the watermarked image on the site, instead of the plain image.

But note that watermark-removal software is easy to write.
Last edited by MidiMagic : Dec 22nd, 2007 at 3:40 pm.
Daylight-saving time uses more gasoline
Reply With Quote  
Join Date: Jun 2007
Posts: 17
Reputation: ghostsquad is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
ghostsquad ghostsquad is offline Offline
Newbie Poster

Re: blocking direct image access

  #6  
Dec 22nd, 2007
Originally Posted by MidiMagic View Post
Security??? I think of security as keeping people from breaking into a computer and doing damage, or keeping them from stealing Social Insecurity numbers. I don't think of someone downloading an image from your page as a security issue, but a copyright infringement.

Something tells me that copyright will disappear in ten years or less, because the Internet will make it cost-prohibitive to enforce.

For your "security" reasons, you should store the watermarked image on the site, instead of the plain image.

But note that watermark-removal software is easy to write.


yes, excuse me. Copyright is what I meant.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Site Layout and Usability Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Site Layout and Usability Forum

All times are GMT -4. The time now is 6:19 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC