prevent来自Apache没有的.htaccess文件访问有的、文件、prevent、Apache

2023-09-02 00:59:01 作者:迷途知返ゝ

(LAMP服务器配置)

(LAMP server configuration)

作为一种变通方法的另一个问题,我需要的PHP能够访问本地文件,但prevent这些文件被通过HTTP阿帕奇。

As a workaround for another problem, I need PHP to be able to access local files, but prevent these files from being served over http by Apache.

通常情况下,我只想用的.htaccess做到这一点,但是由于体制的限制,我不能。我也不能碰的php.ini,但我可以在PHP中使用php_ini_set。

Normally, I would just use .htaccess to accomplish this, however due to institutional restrictions, I cannot. I also can't touch php.ini, although I can use php_ini_set within php.

作为一个创造性的解决方案,我认为,如果执行的PHP作为自己的Linux用户(而不是apache的),我可以正常使用CHOWN的和chmod的做到这一点。

As a creative solution, I thought that if php executes as its own linux user (not as apache) I could use normal chown's and chmod's to accomplish this.

此外,我们的目标很简单,就是有文件,阿帕奇将不会显示一个目录,但是PHP可以访问。

Again, the goal is simply to have a directory of files that apache will not display, but php can access.

我愿意接受任何建议。

推荐答案

下面有一个想法。上设置文件的权限是无法访问到连老板,那么当PHP需要他们, CHMOD() 然后,阅读它们,然后 CHMOD()他们带回无法访问。

Here's a thought. Set the permissions on the files to be inaccessible to even the owner, then when PHP needs them, chmod() then, read them, then chmod() them back to inaccessible.