views:

835

answers:

2

the php fopen fails to open a file for reading, if the file permission is 440. I don't want to give 444 permission to the file, so that it can't be accessed directly through a URL.

+2  A: 

Assuming you are using Apache with PHP, the easiest way around this issue is to limit access to the files using Apache but allow global read access. The way to do this is keep all the files you want off-limits in their own directory, and in the .htaccess file put this:

Order Allow , Deny
Deny from all

Now you can have global read permissions, but if you try to access the file directly from the web you will get a Permission Denied error.

tj111
+1  A: 

You can do as tj111 suggests, block it with .htaccess.

But even better idea is to put it outside of the www root.

For example if your PHP files are in /home/user/public_html/, put your files with limited access e.g. in /home/user/includes giving them 644 (rw-r--r--). You can limit directory permissions to 711 (rwx--x--x), so no one but you can see what files are there. This doesn't prevent you though, from reading or including these files using PHP.

vartec