It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming PHP and MySQL Forum

limited access to files

Moderator: Malcolm

limited access to files

Postby nighthawk on Tue Dec 12, 2006 11:41 am

I'm building a website which will have huge collection of certain pictures :roll: . Only registered users will be able to load that pictures in their browser via php script. The main problem is that I need to prevent users from accessin those images by typing something like this: www.mysite.com/images/image1.jpg into their browser.

Can I do this with htaccess somehow, maybe enable only my php scripts to have access to that folders?
The Zeitgeist Movement
User avatar
nighthawk
250+ Club
 
Posts: 420
Joined: Sun Jun 11, 2006 1:53 pm
Location: SFRJ

Postby rse on Thu May 03, 2007 6:51 am

Hi,

In your image folder you could put a .htaccess file in there with some like like:

Code: Select all
Order Deny,Allow
Deny from all
Allow from 127.0.0.1


This should allow your scripts to access the images but should disallow anyone linking directly to them.

I haven't tested this.

You can also replace the direct linked image with a small image file saying "no hotlinking" etc by putting the following in a .htaccess:

Code: Select all
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain.com/.*$ [NC]

RewriteRule \.(gif|jpg)$ [F] //To simply block access

//OR

RewriteRule \.(gif|jpg)$ http://www.mydomain.com/angryman.gif [R,L] // To send a different image in its place! 


I hope this helps.
Adam Williams
PHP Web Developer

Personal: http://30things.net
Blog: http://www.root-servers.co.uk
User avatar
rse
100+ Club
 
Posts: 141
Joined: Sun Oct 10, 2004 8:15 pm
Location: Leeds, UK

Postby nighthawk on Mon May 07, 2007 2:35 pm

Thanks a lot.
The Zeitgeist Movement
User avatar
nighthawk
250+ Club
 
Posts: 420
Joined: Sun Jun 11, 2006 1:53 pm
Location: SFRJ


Who is online

Users browsing this forum: No registered users and 0 guests