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

时间:2022-04-01 12:41:15

There is a way to keep a text file on my server, but that only my php and python scripts would be able to read it, and if the user just type the url of the file will obtain a forbitten state?

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

I'll like to keep it in the website directory, httpdocs (or httpsdocs, maybe).

我想将它保存在网站目录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)

Tha文件将包含我的数据库用户和passord,以及其他类似的东西:必须是文本格式,因为我需要只有一个文件,但我需要通过多种语言(例如php和python)读取它简单的方法(可能在json结构中)

So doesnt matter if the file extension would be .txt, can be whatever you like more, but i just need that if the users cant go to http://www.example.com/myfile.txt or download it by ftp.

因此,如果文件扩展名为.txt,则无关紧要,可以是您喜欢的任何内容,但如果用户无法访问http://www.example.com/myfile.txt或通过ftp下载,我只需要这样做。

Is this possible, with some apache settings (chmod? maybe not..) or not?

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

3 个解决方案

#1


put a .htaccess file in your directory and deny access to your file like this:

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

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

#2


You could try encoding you text file in Base 64 (or something similar) that's easy enough to implement/has implementations in various languages.

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

See the Wiki article on Base 64 encoding

请参阅有关Base 64编码的Wiki文章

#3


Place the file outer the document directory (e.g instead of /var/www/public to /var/www/private) and give rw permissions to the apach to this dir, but do not enable it in apache.conf

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

#1


put a .htaccess file in your directory and deny access to your file like this:

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

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

#2


You could try encoding you text file in Base 64 (or something similar) that's easy enough to implement/has implementations in various languages.

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

See the Wiki article on Base 64 encoding

请参阅有关Base 64编码的Wiki文章

#3


Place the file outer the document directory (e.g instead of /var/www/public to /var/www/private) and give rw permissions to the apach to this dir, but do not enable it in apache.conf

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