0

I have this very big problem I've been trying to solve for last few days with no success. I have some files which are class schedules, these are imported to the server from an external source (html format). I need to block direct access to those files. They are displayed by PHP script. So, these are assumptions: -files displayed via php script -files cannot be modified in any way (html files) -there must be no direct access to those files -server is apache

any ideas? I tried with htaccess, but I may be not competent enough, because it was blocking access to files for php script too.

Thanks in advance.

4 Answers 4

1

use .htaccess

Sample RewriteRule

RewriteEngine on
RewriteRule ^folder/$ http://path_to_different_page.php 
2
  • thanks everyone and especially You, it is the simpliest and the most efficient way I think :)
    – user1515145
    Oct 4, 2012 at 17:25
  • you are most welcome
    – Champ
    Oct 4, 2012 at 17:28
1

I think another way is :

  1. create a key-value table, rename the file, the old name is key and the value is the new one(may be md5('xx') or other long/irregular/unique string) .
  2. lookup the 'key-value' table when access the files.
0

if you are asking for one or more files protection using .htaccess then you could do something like below ...

AuthName "Restricted Area" 
AuthType Basic 
AuthUserFile /path/to/passwordfile/.htpasswd 
AuthGroupFile /dev/null 
<Files admin.php>
require valid-user
</Files>
<Files protected.htm>
require valid-user
</Files>
<Files protected2.htm>
require valid-user
</Files>

You'll need to create one .htpasswd file too and update the AuthUserFile path to location of this file .... There is a tool availabe at http://tools.dynamicdrive.com/password/ to create these .htaccess and .htpasswd files.

0

files displayed via php script

Store the passwords somewhere (securely). HTML form to submit credentials. $_POST to read them. PDO to read them. include to include the files if the user is authorised.

-files cannot be modified in any way (html files)

All the logic goes in PHP. All the credentials are stored externally.

-there must be no direct access to those files

Keep the files outside the DocumentRoot.

You must log in to answer this question.