Link to home
Start Free TrialLog in
Avatar of nodreads1926
nodreads1926

asked on

How to implement simple password protection with PHP

Im trying to implement the maxSiteProtector PHP script on my website. http://www.phpf1.com/product/site-protector-script.html 

STEPS SO FAR
1.      Ive included the maxProtector.class.php file, and style folder in the same folder as my HTML files for my site.

2.      I have added the following line to my HTML files: <?php require_once("maxProtector.class.php"); ?>

3.      I have confirmed php is enabled by my hosting site by accessing www.mysite.net/html/maxProtector.class.php via my browser and seeing the same screenshot as on the product page above AND by creating and viewing a  hello world echo script.

EXPECTED RESULT
I now expect entry to my pages at  www.mysite.net to require a password, but they dont.  

QUESTION
What am I doing wrong?

I've renamed the php file to .txt for upload and attached it.

Open in new window

maxProtector.class.txt
Avatar of Beholdason
Beholdason
Flag of United Kingdom of Great Britain and Northern Ireland image

have you tired changing you .html file to .php file to see if that makes a difference
Avatar of nodreads1926
nodreads1926

ASKER

Beholdason:
I have various pages in the HTML folder, all of which I want to protect. Do you mean renaming those?
For example:  "www.mysite.net/html/index.html" to "www.mysite.net/html/index.php"?
Thanks
Yes that is what i meant but i had a look into the Max's site protector and it shouldn't be necessary.

what is exactly wrong is your pages viewable without the a password.

be sure maxProtector.class.php is in www.mysite.net/html/ 
Reply to Beholdason:
1) yes, maxProtector.class.php is in www.mysite.net/html/
2) yes, the problem is that the pages are viewable without a password.
maybe there is a error with the php script i can't see try using a different script like

http://www.phpbuddy.com/article.php?id=23

If you just call it maxProtector.class.php will save you having to change all your pages
1) I copied the code at phpbuddy to "password_protect_page.php" and put it in www.mysite.net/html
2) I included the line "<?php include "password_protect_page.php"; ?>" at the very top of my "index.html" and "page_2.htm" files.
3) I went to www.mysite.net and could access it without a password. In fact, there was no sign of the php script operating.
4) I COULD view the pag when I typed in www.mysite.net/password_protect_page.php
Step 4 was a little surprsing. I was expecting to have to include "/html" in the path, e.g.
www.mysite.net/html/password_protect_page.php
I tried to put the php file directly into www.mysite.net, but received the ftp error
Response:      553 Rename/move failure: No such file or directory
Error:      Critical error

What version of php is your server running?

Seems like it isn't parsing the php at all
But it runs the pages  "hello world" and "password_protect_page.php". So it must be parsing the php, right?

ASKER CERTIFIED SOLUTION
Avatar of Beholdason
Beholdason
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
i just tested it with max's site protector aswell and it was the same problem
OK, this seems to do the trick.
One problem (urghh) - all the links between pages now have to be renamed from ".htm" to ".php"
Any ideas on how to do this easily?
Nice work with the other problem.

The way i do that kind of thing is open my files in notepad or a similiar text editor depending on your operating system and search and replace .html with .php
Doh!
Full points to you.
Thanks and good night.