Jump to content

Restrict access to folders/files


einherjer

Recommended Posts

Hello everyone,

 

I was wondering if anyone could help me with the following problem:

 

On a website, I will have several PDFs that I need to make available if user gives correct password or is in a given IP range. My first thought was to use .htaccess, but the host doesn't support that. they do support .htconfig and I didnt find any way of using that to resolve my needs.

 

If there any walk around in this situation using PHP and MySQL?

Link to comment
https://forums.phpfreaks.com/topic/47494-restrict-access-to-foldersfiles/
Share on other sites

You can find the user's ip address in $_SERVER['REMOTE_ADDR'].  If they are using a proxy server, this will be the address of the proxy server.

 

For password authentication, you can implement this yourself in php, providing php is running as an apache module.  Details are here:

 

http://sg2.php.net/features.http-auth

Oops, I forgot to mention - if you're using php to do the authentication, then your script will have to print out the file as well.  The files can be kept somewhere that can't be accessed via the webserver.  If you simple link to the file, then someone who knows the link can simply download it directly.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.