Click to See Complete Forum and Search --> : password protect txt file


phe
06-18-2008, 02:06 PM
Hello, I have a simple php form that is saved as a flat .txt file.
The reason for this method is that I use it as a notepad on my website.
My question is: can I hide or password protect the .txt file so that no one else can view it?
The php form is protected.

Hope someone out there has an answer!

felgall
06-18-2008, 04:30 PM
You can't password protect the file itself but you can password protect the folder it is in so that only those who know the password can access files in that folder. PHP will still be able to access the folder to write the file without needing the password.

phe
06-19-2008, 01:15 PM
that's what I thought. So how does one password protect a .txt file?
Can I write some code in a seperate php file?
I don't need the .txt file to be viewed at all.

phe
06-22-2008, 08:29 AM
Appoligies, I misunderstood the first time.
So I need to password protect the folder the .txt file is in.
The path to the folder is: notes/text.txt
So the folder it is in is 'notes'.
I would like to protect this folder with php if possible, so far I am failing. Do you have any suggestions?

ps: I am not using a database.

Stephen Philbin
06-22-2008, 02:16 PM
Assuming you're using the Apache web server, you don't need a database or PHP. You can use what's called "basic auth". You use an Apache web server configuration file to tell it not to serve any files from a folder unless the user has been authenticated.

Which file you use to set this configuration will depend on your hosting and the degree of control you are allowed over your host. If you have complete control over your host, then it would be best to use the "httpd.conf" file. If you are limited in what you can do with your hosting, then you'll probably have to use a file called "htaccess".

In either case, you can find plenty of helpful information in the Apache 2 web server's basic auth manual section (http://httpd.apache.org/docs/2.2/mod/mod_auth_basic.html).

If you're not using that version of apache, then just follow the links to the main page and select the version you are actually using.

phe
06-22-2008, 02:58 PM
Thank you so very much for your help.

I am new to htaccess and I must say very surprised at how easy it is to use.
My problem is now solved.

htaccess is going to come in very handy in the future with most of my projects.