views:

88

answers:

3

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?

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

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)

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.

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

A: 

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

See the Wiki article on Base 64 encoding

Binary Worrier
A: 

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

erenon
+3  A: 

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

<Files file.txt>
Order allow,deny
Deny from all
</Files>
Jack
This works perfectly!
DaNieL
Oh, just a detail: it works if the file.txt is in the same folder of the .htaccess (website root), but if it is, for example, in a subfolder? like /var/www/vhosts/example.com/httpdocs/myfolder/file.txt ? i've tryed with <Files myfolder/file.txt> but doesnt work
DaNieL
I think you'll have to put a .htaccess in the subfolder for that.
Jack