Protecting files without htaccess

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
thiscatis
Forum Contributor
Posts: 434
Joined: Thu Jul 20, 2006 11:00 am

Protecting files without htaccess

Post by thiscatis »

Hello,

is there a PHP way to protect files, jpegs, pdf`s etc.. without htaccess because i already use a custom login/member management.
So the files are login-protected even when they know the exact link to the file.

Thanks!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

If the exact link to the file is known.. nope. Use a script as the interface into the files. Place an .htaccess in their directory that disallows all access (not password protection).
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

...or move them outside the web root, but everything else is exactly as feyd suggested: use a gateway/interface script that authenticates and initiates the download.
thiscatis
Forum Contributor
Posts: 434
Joined: Thu Jul 20, 2006 11:00 am

Post by thiscatis »

so for example:

I have a gallery that loads images from the /gallery/ folder.
I place a htaccess in the /gallery/ folder to prevent direct access.
So people will need to be in the gallery system to view the pictures.
Will that work? or will the htaccess prevent the script from loading pictures.

(gallery/picture as example, could be something else too)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The .htaccess file will not stop PHP from reading the directory, only requests Apache would handle.
thiscatis
Forum Contributor
Posts: 434
Joined: Thu Jul 20, 2006 11:00 am

Post by thiscatis »

Great, I`ll know what i'll be making today :)
You guys are better than google, learned a lot here, thanks!
Post Reply