Forum Moderators: mack

Message Too Old, No Replies

Preventing pages from being accessed

         

frozenwaste1

12:00 pm on Jun 21, 2007 (gmt 0)

10+ Year Member



Hi,

I'm pretty new to site developing, in fact just built my first one.

I have a question regarding protecting certain pages, here's my config:

My site has a form which collects certain user details. When they click submit, I use PHP to email me the details but to also add them to a text file.

Now here's the problem, I want the text file to be for my use only, however anyone can type in www.site.com/text.txt and it opens up for them! How do I go about protecting the text file so only I can open it up?

Or am I going about things completely the wrong way!

Thanks for your time.

vincevincevince

12:09 pm on Jun 21, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Four simple solutions:

1) Put it above the web root - when you go with FTP you probably have to click into 'html', 'www', 'httpdocs' or similar to get to the directory where your index file goes. Assuming this is the case, put the file ABOVE that directory, i.e. where it is inaccessible via your domain name. Read it by FTP download.

2) Use a MySQL database and store the file in there

3) Rename text.txt to text.php - for security - add <?php die();?> to the top - then anyone who visits will see nothing at all - and when you download via FTP you will get everything.

4) Use a .htpasswd and .htaccess combination - use your favourite Search Engine to find out more about these - they are simple password protection for the directory

BeeDeeDubbleU

1:19 pm on Jun 21, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If you are receiving an email with the details then why do you need to also write it to a text file?

frozenwaste1

3:28 pm on Jun 21, 2007 (gmt 0)

10+ Year Member



Thanks very much, I'll give a couple of them a try. Did look at MySQL, but looked a bit in-depth for me at the moment!

As for wanting the data to be sent to a text file, I just wanted a backup of the data, and a file where I could check all the data (until I have a MySQL DB up and running)!

Thanks.

londrum

8:19 pm on Jun 21, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



if you write it all to a file you have to be careful of other things as well -- like writing to it at the same time as you are opening it and stuff like that. you could corrupt it, or lose some of your data.
you need to look into file locking it whilst your doing something on it.
...depends how busy your site is though. if it doesn't get written too all that much then you'll probably be alright