如何保持文本文件只能从php和python中读取,而不是用户?

时间:2009-06-05 06:40:00

标签: apache permissions configuration-files

有一种方法可以在我的服务器上保留一个文本文件,但只有我的php和python脚本才能读取它,如果用户只输入文件的url就会获得一个forbitten状态?

我想将它保存在网站目录httpdocs(或httpsdocs,也许)中。

Tha file will contain my database user and passord, and other stuff like it: must be in text-format becose i need to have just 1 file but i'll need to read it by many languages (php and python for example) in an easy way (probably in json structure)

如果文件扩展名为.txt,那么无关紧要,可以是你喜欢的任何内容,但如果用户不能转到http://www.example.com/myfile.txt或通过ftp下载它,我只需要它。

这是否可行,有些apache设置(chmod?可能不是......)或不是?

3 个答案:

答案 0 :(得分:3)

将.htaccess文件放在您的目录中并拒绝访问您的文件,如下所示:

<Files file.txt>
Order allow,deny
Deny from all
</Files>

答案 1 :(得分:0)

你可以尝试用Base 64(或类似的东西)编写你的文本文件,这很容易实现/有各种语言的实现。

请参阅Base 64 encoding

上的Wiki文章

答案 2 :(得分:0)

将文件放在文档目录外(例如,而不是/ var / www / public到/ var / www / private)并赋予对该dach的app的rw权限,但不要在apache.conf中启用它