zubrag.com
Free php and cpanel scripts to automate your daily routine

Free PHP Scripts :: Web Page Password Protect

Password protect your content with Web Page Password Protect by just adding one line of PHP code to your page source. Script will present user with password entry form, and will not let visitor see your private content without providing a password.

Multiple user accounts support, improved security, automatic logout, and manual logout feature.

Usage:
  • Save password_protect.php somewhere on your server
  • Update it with your desired password or login/password pair. Use any plain text editor to accomplish this step. Sample editors: Notepad (Windows) or vi (Unix).
  • Open script in your browser with "help" parameter to see the line of code to add to every page you would like to be password protected.
    Example: password_protect.php?help

    It will show you protection code to include into your pages. Sample protection code would look like this (yours will be different):
    <?php include("/home/users/htdocs/security/password_protect.php"); ?>
  • Add that line of code to each php page you would like to protect at the very beginning of the page source (it must be the first line).
    For example you want to protect page protect-me.php. Open it for editing, and add the protection string (see above on how to get the protection string) at the beginning. So resulting code would look like
    <?php include("/home/users/htdocs/security/password_protect.php"); ?>
    ... here, at the second line starts your page code ...

Find more detailed description on how to setup password protection script on the forum.

Download Web Page Password Protect


Comments

August 5, 2000
Awesome script. i just used it on my site and it works great. really simple to set up.

thanks
nick
July 28, 2006
Excellent! Nice and simple, but well worth it!
Mark July 29, 2006
Great script, but it would be ideal if a cookie was set so the user didn't have to re-enter the password when navigating through pages in a directory.
Just a little annoyance, other than that it did its job nicely.

zubrag: Changed script according to Mark's suggestion. Now it supports cookies and requires password only once.
Mark July 30, 2006
Wow, now that's what I call support!

Very well done, thanks a bunch!
Jvuz August 2, 2006
Just a question, can you also add different users?
Jason August 3, 2006
Great script! thanks a bunch! worked perfectly
sundberg [anti-spam] inlife.se August 4, 2006
Where do i put "password_protect.php" ?
Does it need to be put in a secure catalog, maybe outside the webroot?

zubrag: you can place it where you want. Outside the webroot or in a secure catalog would be good. But script will not reveal the password, no matter where it is placed.
FrEaKmAn August 5, 2006
Can we modify this so that we can also include username? I'll try myself but I need help!

zubrag: Added multi-user support. Now Password Protector can either ask password only or login/password pair, depending on settings.
August 6, 2006
How can I get the code to re-direct the user after login (into a subdirectory, for example)?
zubrag August 6, 2006
Ok, you can use this tool as redirector (though it was not designed for this). If you want to redirect to some folder after visitor login, then add following line just before the last ?> line
header('Location: http://www.yourdomain.com/redirection/path/'); die();
August 6, 2006
Thanks! Will try that soon... excellent site, helpful admin!

Thanks again!
dave [anti-spam] sweetser.com August 6, 2006
Hi,

Your password PHP script looks good and I want to use it at GoDaddy.com, my hosting service. So I created a PHP folder at www.abc.com/PHP

which is where I put the script. However, the example include line starts off with:
include("/home/users...")

How (or if) does "/home/users..." relate to what I need to work with: www.abc.com

In other words, I don't have access to any root folders. From my perspective, everything is based at www.abc.com. Given that, what would the path look like in the include statement? Again, how would a web page point to the PHP script when its location is basically a URL, not an absolute path.

Thanks.

Dave

zubrag: In order to get your path for include statement open it in browser passing "help" parameter, i.e.: http://www.abc.com/PHP/password_protect.php?help
It will show you the code to include in every webpage you would like to protect.
Cindy August 8, 2006
I must be really dense - where in the code do I put the include("/home3/marilou/cc-ob-www/elder-connect/password_protect.php");?
And correct me if wrong, I would change password_protect.php to the page name I wish to protect.

Do I put this:
die('Include following code into you pages: <br /><b>include("("/home3/marilou/cc-ob-www/elder-connect/password_protect.php");</b>');
like that?

zubrag: in order to see protection code you should open script in browser. From the code you provided it seems like you invoked it from shell (terminal), that is why it shows a lot of things you would not see when opened in browser. In your case just add include("/home3/marilou/cc-ob-www/elder-connect/password_protect.php"); to a webpage you want to protect.
August 12, 2006
Where do I find the final code you modified to include the login/password pair and the cookie support?

zubrag: Use download link above. All changes are already included.
Gwen August 13, 2006
Where do I put the correct password? Do I add all that code to every page of my website?
Gwen August 13, 2006
I added this code in the HEAD part of the page and it isn't working. Did I put it in the wrong place?

<?php include("/usr/hsphere/local/home/gwen1224/shalitraining.com/password_protect.php"); ?>

do all my pages need to be .php pages. Right now they are .htm pages.

zubrag: Yes, script can only protect php pages.
Gwen August 13, 2006
Okay got it all, looks great, works great. You are awesome!!
Marsha August 13, 2006
I am getting this
Warning: Cannot modify header information - headers already sent by (output started at /data/web/virtuals/.........

Line refers to the cookies portion

setcookie("verify", md5($pass));

what to do ? Everything else is working it's just that line seems not come up with the error.

Can I get the script without the cookies from where should i take off out of the code.

zubrag: this means something goes to output before password_protect.php is run. To avoid setting cookie add // before setcookie so resulting line will be
// setcookie("verify", md5($pass));
Marsha August 14, 2006
Thanks alot for the response, it worked well, I am so happy!!!
PaulM August 15, 2006
I have a similar problem to Marsha. I get the "Warning: Cannot modify header information - etc" referring to the style line that precedes " input { border: 1px solid black; }".

I am sooooo close to having this working perfectly.
zubrag August 15, 2006
try putting your protection string at the VERY BEGINNING of the file in following format:
<?php PROTECTION-STRING-YOU-RECEIVED-FROM-PASSWORD-PROTECT-WITH-HELP-PARAMETER ?>
PaulM August 15, 2006
I don't have a problem with the protection string. That seems to be working fine.

My problem is in the password_protect.php file that I have named index.php. As I downloaded it, after filling in the password you are just left with a blank page. I wanted it to then redirect to a page called index2.php. The PHP header command won't do that because it cannot have anything else written to the screen first.

How do other people use this script?

zubrag: Script was not designed to redirect, but it may redirect after login if you add the PHP "header" command like mentioned in comments above.
Main purpose of the script is protecting information on php pages. In order to protect web page you need to change that webpage source code (add protection string). If you need to protect few php pages then add protection string to each page. Please refer to "Usage" section at the top of this page for details.
Dhani August 17, 2006
Can you please include the options for "logout". Like having the logout button or something?
Dhani August 17, 2006
And one more thing, can I specify one page just for one user in user list array?
Dhani August 17, 2006
what I mean, one page to protect just one user from the user array list who can access it?
zubrag August 17, 2006
This script can protect only on page by page basis. So if you want to grant access: user A - webpage A; user B - webpage B, then this can be accomplished as follows. Copy password_protect.php to protectA.php, and include protectA.php in webpage A. Copy password_protect.php to protectB.php, and include protectB.php in webpage B. In this way you will be able to give user A access to only page A, and user B will only be able to see page B.
Dhani August 18, 2006
and how about the logout options?

this script is what I need, one more thing is the options to include the logout procedure...

zubrag: It will auto-logout when browser window is closed. Adding logout button/link is not so obvious... Will need to think on how to implement it so that it worked good for everybody.
August 20, 2006
How could I set this up to protect my blog (powered by simplephpblog) on my home server running Abyss Web Server?
Regards
Filthio August 21, 2006
Congrats on an awesome script. And so easy to use. I had the same problem as Marsha, with "Cannot modify header information". However I did as you suggested and put the include right at the very start of the document. It worked perfectly. Thanks.
André August 22, 2006
I'm getting two errors;
1) Cannot modify header information...
I uncommented the setcookie thing, and the error was gone.
2) Fatal error: Cannot redeclare showlogin() (previously declared in /home/bla..bla..bla../admin/password_protect.php:108) in /home/bla..bla..bla../admin/password_protect.php on line 108

The line goes like this;
function showLogin($error_msg)

Any idea?
André August 22, 2006
Too many include files I guess.
zubrag August 23, 2006
Andre, seems like you are including it few times in one file. Unfortunately our programmer is currently not available, so I slightly updated script myself. Please download new version. If it does not work for you then please check back in few days.
zubrag August 23, 2006
In order to protect your blog (powered by simplephpblog) you'll need to find some file which is included into all blog pages (this is usually some settings file), and add protection line to that file. Unfortunately I'm not familiar with simplephpblog, so cannot give you more details.
Dhani August 24, 2006
how about adding some parameter into the page.php script that passing the parameter into functions in the included password_protect.php, like:

page.php?logout=1

ps: sorry if I so much to ask, but Im not good enough on PHP... thank you in advances...

zubrag: Nice suggestion Dhani! Thanks. We'll add it on Monday.
Gwen August 26, 2006
Okay, I accidentally overwrote the password_protect php file and can't figure out how to have it ask only for a password and then where to put the password I selected.

zubrag: open password_protect.php in editor. Find SETTINGS START section. If you want to ask password only then USE_USERNAME should be set to false: define('USE_USERNAME', false);

and update passwords array to what you need. Below I'm allowing access with two passwords: root, and adminpass

$LOGIN_INFORMATION = array(
'root',
'adminpass'
);
Burke August 27, 2006
Trying to build the $LOGIN_INFORMATION array from a MySQL database.

This builds the string correctly:

$unpw = $unpw."'".$username."' => '".$password."', ";

then srtip the comma from the end

$unpw_array = rtrim($unpw, ' ,');

Then
$LOGIN_INFORMATION = array($unpw_array);

But it doesn't work. The $unpw builds correctly but when it's added to the (array) it does not work.Do you need CR/LF at the end of each entry?

Suggestions?
zubrag August 28, 2006
Example on how to do it based on MySql (this code is not working as is, needs changes to connect to database, and to match your database table/fields names):

$query = "SELECT * FROM USERS-TABLE-NAME";
$result = mysql_query($query);

$LOGIN_INFORMATION = array();
while ($row = mysql_fetch_assoc($result)) {
$LOGIN_INFORMATION[$row['USERNAME-FIELD-NAME']] = $row['PASSWORD-FIELD-NAME'];
}
August 29, 2006
Hi,

First of all, a great script - just what I was looking for! However I am having a little difficulty.

I have placed the file "password-protect.php" in "127.0.0.1/~chris", and when I browse to it I get the prompt to enter a login and password. Instead I change the address to "http://127.0.0.1/~chris/password_protect.php?help" as directed. However, the page doesn't give me the include address, just "Include following code into every page you would like to protect, at the very beginning (first line):".

Apache and php are up and running on my machine (OS X), as can be confirmed by opening other php pages on my machine. Have you got any suggestions as to where I'm going wrong?

Many thanks, Chris

zubrag: Fixed. Please download it again. Thanks for your help!
August 30, 2006
Works like a dream now. Thank you very much for the script and prompt reply.

Chris
sarkarsweet [anti-spam] gmail.com August 30, 2006
Hi Zubrag, Thanks for the simple but useful free programme that I have been looking for use.
However, I downloaded it, but do not understand what do I need to do use it for a particular page - only with Password (without any log-in) by spl friends using my Homepage. I viewed the write-up using notepad, but am unable to proceed further! (needles to mention my amateur status).
Will appreciate advice - my e-mail is: sarkarsweet@gmail.com
All the best - Ashit Sarkar (Bangalore)
sarkarsweet [anti-spam] gmail.com August 30, 2006
Further to my earlier msg I have noted that Updating can be done to the file . However, what I cannot figure out is how to:
"Open script in your browser with "help" parameter to see the line of code" - as instructed.

I use Firefox, and the help button is of no help about 'script'! Obviously, I am floundering...

Thanks - Ashit.
ronatola September 1, 2006
hmmmm...this is exactly what I am looking for but...
Like a pervious post, I am using godaddy to host my website. I ftp'd in and created a php folder and dumped the password_protect.php file there. However, when i open the http://www.1234.com/php/password_protect.php page i get a 404 page.
Any ideas? Does my host need to activate php somehow?

Ronatola.
Ronatola September 1, 2006
EDIT TO PERVIOUS POST:
http://www.1234.com/php/password_protect.php comes up as all text and http://www.1234.com/php/password_protect.php?help comes up 404
zubrag September 1, 2006
Ronatola, if it comes up as text/404 then you have no php support enabled. And this tool can only protect php files. Contact your hoster, maybe they want php files to have another extension, like php3, phtml, etc. If they does not support php then you'll need to password protect with JavaScript. We are going to develop such solution in few weeks.
Nils Ingvarsson September 6, 2006
Hi,

For a PHP novice like me, this script saved my day! Works like a charm. Easy to implement with the provided instructions. And thank you Zubrag for keeping it free. Good job!

For people interested in design, this script is easily implemented in your current webdesign. (It need some tweaking to validate as XHTML though.) Just replace the HTML code in the password_protect.php file with your own. This way you can customize the login page any way you want. Remember to keep all PHP and META code ;)

Here's my try: http://www.utblas1.se/formedlemmar.php
It's in Swedish, but you see what can be done.

Best Regards
Nils Ingvarsson
Jönköping, Sweden
lost September 15, 2006
I am trying to use this code for a blog, and am a real ameteur. What's the best way?
YOURE THE BEST!!
Terry September 17, 2006
This script can be used only to php pages? I have html pages on my site. How can i convert them to php?
September 19, 2006
Thanks you, Work Great.

-Dom
September 20, 2006
why doesn't the password work except for the last line in the code?

$LOGIN_INFORMATION = array(
'' => '123456',
'' => '654321',
'' => '789456123'
);
Claire September 21, 2006
// check if cookie is good
$found = false;
foreach($LOGIN_INFORMATION as $kay=>$val) {
if ($_COOKIE['verify'] == md5($val)) {
$found = true;
break;

In the fourth line it says $kay for the array. Should this be $key?

I am just learning php, so am not sure.

Thanks.
September 21, 2006
it still doesnt work
Brian September 23, 2006
I was wondering if there would be a way to save the login in the cookie so that you could access the cookie and know who was logged into the system. Is there any way to do this?
September 25, 2006
you rule. all i found was apache .htaccess stuff and thot "why isn't there something simple like (insert your beautiful script here)?" thanks for sharing, the world is a better place for it.
Parag September 25, 2006
Well done. You script rules!
Short, well-scripted, tidy and does the job fine and easy to use.Thanks for coding/sharing it.
Plz delete this entry if you want to so that other can find support easily.
jack886 [anti-spam] gmail.com September 27, 2006
hello,
The password protected page is stored in a sub-directory, when I test to click that protected page, it just go in directly without asking login name and password, what can I do about it? Is this correct? <?php include("/home/stingyan/public_html/password_protect.php"); header('Location: http://www.the-speedperformance.com/products/A-BV01.php'); die(); ?>

Please advice, thank you a lot!!

Jack
Beezer September 27, 2006
After I unzip the file it saves it as Microsoft Picture It! file.
Doesn't look like anyone else has this issue. What program do I need to open the file correctly?
Beezer September 27, 2006
I was able to open the file with Edit Plus Text Editor. Thanks.
Junaid September 29, 2006
greatgreatscript
Junaid September 30, 2006
the script is working perfect for redirecting .html pages but it fails to redirect to a php page
Niyi October 8, 2006
Nice script...thanx for sharing.

How can I use this script with php/mysql database login array. The example above is not really explanatory enough for a novice like me. Thanks
nisha October 10, 2006
hi,
zubrag can you please help by writing ftp creator script also? plz plz
surveyjon [anti-spam] westnet.com.au October 10, 2006
Just a slight problem.

Trying to protect 2 pages with different passwords. Have set up seperate protect pages but once one password is entered, both pages are accessible.
Ellen October 11, 2006
What if I don't want to enable the cookie? What code do I change? I'm only using it on one page in my site.
Squid October 11, 2006
surveyjon, i would add at line 105 this... $gpg = $_GET ["gpg"]; and add to the all the cookie information md5 ($val.$gpg) Lines 118, 133. Then when you call the file use <?php include ("path/to/file/password-protect.php?gpg=XX"); ?> I have not tried this yet, but it should work for multiple pages with different codes.
jerome.law [anti-spam] ipsolutionsltd.com October 25, 2006
Many thanks..this is so sweet. Now I want to try to protect my documents. Can I use the same way? Thanks. Jerome
BigGoga October 28, 2006
Very good and usefull script!!!
I have developed it a little. My version bans users IP after 3 uncorrect passwors input. Last banned address is stored in a text file.
If someone is interested in it. I can share my work :)
November 2, 2006
how do I include the password list to accept?

zubrag: open script code for editing in some editor (like notepad, vim, etc.), find SETTING START section, and update it according to comments in the header.
andrew.vos [anti-spam] gmail.com November 8, 2006
why doesn't the password work except for the last line in the code?
I am having this problem too!!

zubrag: Documentation problem. List only passwords when usernames are not in use, like shown below
$LOGIN_INFORMATION = array(
'protected',
'my password'
);
alexcie_larry [anti-spam] yahoo.com November 10, 2006
Hi Its a Great Script you have But i have one question.. I use FRONTPAGE @))# to edit my site can i use your script to protect pages?? Thanks very much
November 15, 2006
Can we use PHPSESSID to protect the pages?
This suggestion is a alterative to the current Cookies Protection.
Emma November 16, 2006
Hi, I must be having a blond moment sorry. Where do I change the password and username to what i want? Is it: I tried but it didn't work.

'zubrag' => 'root',
'admin' => 'adminpass'

?
November 18, 2006
Hi I set this up it looks like it's working but it will not accept any passwords? with no changes to the script I assume the default is.
zubrag
admin
help
doug.turner [anti-spam] nadel.com November 21, 2006
Fantastice script! is there away to set the password to any number between two specific numbers. I need the script to let in multiple users. Thanks
frankkthetank [anti-spam] gmail.com November 26, 2006
Ahh, I'm sorry, I have no idea how to do this.
Could it be explained easier to me?
Thanks in advance
December 3, 2006
Hi
Great script Zubrag
Nice and simple
Just a couple of quick questions

Can it be changed to prtect html files or do I need something different? I know this has been asked already but saw no answer

Is it possible to restrict the number of times the user has access? EG. I set it up on a page which outputs codes, but how do I alter it so if the user wants to get more codes, they need to contact me again/re-purchase

Mick
December 6, 2006
You can convert an html file to a php file in most cases simply by saving it as a php file in dreamweaver. (Maybe frontpage too, although i'm not sure about that).
fred [anti-spam] lentjes.com December 14, 2006
I an't get the script working. Where do I put the username and where the password?
Jake December 14, 2006
I put this on a Journal Entry Form that I have and I type in the username/pass just fine, type my journal entry, but then when I hit submit, it brings me back into the the login page, then I have to type in username/pass again and then it submits my journal entry. Anyway to change that?
Jake December 14, 2006
Delete my comment. I put the line of code in front of when it should have been at line 1, missed that part. Sry.
sales [anti-spam] prismimages.net December 17, 2006
hi i dont have a clue in the slightest with php but i have a few pages on my site and i want the user to be able to login and depending on their username or password depends on the link that it goes to. say the user name is cat it will go to cat1.php and if it is dog it will go to dog1.php

i cant find anything that can do this without using mysql.

Thanks
Lee
sales [anti-spam] bradfordtradecentre.co.uk December 19, 2006
hi i am trying to secure a admin folder in my ftp how do i do this ive tried putting the script in the folder but its not working
Luke December 19, 2006
You must be the smartest PHP Programmer on earth. Why didn't anyone think of this before??? I've been looking for this exact script since php3... Thank you, thank you, thank you!
Frank December 20, 2006
Simple but awsome ....
A magnificent work
contact [anti-spam] digitalsun.us December 26, 2006
Great Script! Thank you!
Just one question. I get this error: Warning: Cannot modify header information - headers already sent by (output started at /home/content/j/a/n/janepark/html/uploadScript/fileUpload.php:3) in /home/content/j/a/n/janepark/html/uploadScript/password_protect.php on line 120.

how do i fix this?
Greco December 28, 2006
Greco
I have never used PHP ... But this script sounds fantastic!!!
I have renamed the HTML page as PHP. Will it work?
January 4, 2007
How would you get directly into this page without the popup? Straight from URL?

http://yourwebsite/page username=? password=?
Amanda January 4, 2007
Thanks for this script. It works with Frontpage, I just changed the file extension on an already created .htm page to .php and it works like a charm. So easy!
Tom January 5, 2007
After logging in with your script,
I cannot log out. Neither: include (password_protect.php?logout) nor
setcookie("verify",' ') worked. Once
logged in, I can then always see the protected form. What am I doing wrong?
Many thanks.
lafhog January 7, 2007
Hi
Great script Zubrag
Short and simple
Just one quick question
is it possible to password_protect a Folder or Dir, to just display that folder and all its files.
Lafhog
January 10, 2007
that is perfect!!!! thanks a lot
January 10, 2007
Hey This thing is great But, I inserted the code to my page and it worked the first time, but it doent work any more. Please Help. It just shows a white screen instead of the Password log in form
Regulus January 13, 2007
It's a great script, exactly whay I am looking for. But just wondering if the number of paswords you can include on the script can be unlimited or not. I intend to include as many as 45,000 passwords on the script. Is this still possible?

Thanks for the great work on the script
January 15, 2007
Great script! It works perfectly. Thank you so much!!!
~Cindy
jerboyd [anti-spam] sympatico January 17, 2007
hi. thanks for this script. i am using it to protect a members only area of my site but i would like to have two levels of security. so some pages are available to anyone who logs in and some are abailable to people who log in with a second security level. is this possible? also how can i have a form for a user registration. thanks for your time
admin [anti-spam] egold-biz.info January 18, 2007
Hi, did I get it correct - that this script will only work to protect php webpages. So I cannot use it to protect my page if it is written in html?
Ange January 26, 2007
Holy cow! I am not a programmer, but it worked perfectly for me. Thank you thank you thank you!!!
January 29, 2007
Great programming!
JBone ~ Majerwebs January 29, 2007
Script is perfect
florence January 30, 2007
Thanks you, Work Great. And you're great

Flo, from France
rscott [anti-spam] nwdusa.com February 1, 2007
Big Goga,

Would really like to see what you had done for the reject IP address after 3 incorrect password attempts.

Anyone,

Anyone modify this to use Session ID rather than cookies???

Zubrag,

Great Script. The awesome functionality lets us breathe a little easier here...

Thanks,
Rich
Shawn February 6, 2007
I've tried to edit the cookie portion out of the script to no avail. I would like the script to always require the user to provide a username and password. Some way to easily comment out or disable this feature.

Thanks, for a great script!
azearly February 13, 2007
Using password only, can only enter 3 passwords out of 4 that i want to use.
How do i get the forth password to validate?
maurinet February 15, 2007
Zubrag: this script is awesome! Thanks a whole lot!!!
Small question: is there a way to protect a folder with this same script? (I'm using it for a webpage with pictures, and it works gerat, but somebody can still write the address of the directory and access the photos).

Thanks in advance,
|¥|@µ®¡
Werewolf_NC February 16, 2007
I can't put in my own name and passwords into the script. If I change anything in the password_protect.php script the login page won't load at all. Am I doing something wrong for the name and password?
February 19, 2007
Thanks it worked well but It would be great if you also made it so you could make an option for no cookies.
February 23, 2007
How secure is this please? I really love the simplicity of it, just want to know that it is safe.
fallen_angel February 27, 2007
Excellent script! Works flawlessly! Kudos to Zubrag.

This can be used on htm/html pages if you add a handler into your .htaccess file -

AddHandler application/x-httpd-php .htm .html
March 4, 2007
wow, great code -- you just made my life a lot more simple, thanks!!
March 11, 2007
Very clean. what else can I cay?
cate March 12, 2007
this is an amazing code ! clean, easily customizable, etc. perfect.

is there any way to clear the cookie once a user navigates away from the server, so they have to re-enter it the next time they come back?

like, say my site was site.com. when i leave site.com and go to blah.com, it stops saving the cookie so when i return to site.com, i have to enter the password again.

thanks !
Lew March 13, 2007
Zubrag; Great code. Thanks for your efforts. It really helped me out. Its coders like you who make the web work.
Noswombat March 14, 2007
Thank you soooooooooo much......I used it for .htm pages and it worked a treat
osourcem March 14, 2007
i've got some problem as others:
Warning: Cannot modify header information - headers already sent by (output started at /home/blabla/domains/blabla.com/public_html/apsauga/testas.php:2) in /home/blabla/domains/blabla.com/public_html/apsauga/password_protect.php on line 118

how to solve this? i removed header from the page which has to be displayed after login prompt
March 18, 2007
does this script filter mailicious input?
March 19, 2007
Question:
I want to password protect a URL page to be accessed from eBook.
I want the access to be transparent to user ie. the reader just clicks the hyperlink to the target webpage WITHOUT being presented with, and having to, enter any user id or passwords! (in other words, these are already pre-set in the page).
Reason is to prevent accidental stumblers onto my webpage but allow book readers to access via the hyperlink click.

Will this do it? How to protect the target URL destination?
roysorin [anti-spam] gmail.com March 20, 2007
hii this is very good system login :)
March 21, 2007
Thanks much for making this, Zubrag!!!
March 23, 2007
Thank you so much for the great script, it's just what I was looking for.
A question though - Once a user logs in, they are permanently logged in, it seems. I would like the users to be logged off once they navigate away from the protected page - I would like the script to always require the user to provide a username and password.
root [anti-spam] olgiatipy.org March 24, 2007
Posting this in case it may help some others who want, like I did, to password-protect pages written in HTML

If the page you want to protect is HTML, there is a quick and nasty way to turn it into a .php page:

Add the following two lines before the first line of the HTML page:
<?php
print <<<END_OF_HTML

add the following two lines after the last line of the HTML page:
END_OF_HTML;
?>
and save the resulting page with a .php extention.

You now have a .php page, which you can protect by adding the line:
<?php include("/directory/of/your/web/site/password_protect.php"); ?>
at the very beginning (after of course changing /directory/of/your/web/site/ to suit your local situation).
Graeme March 25, 2007
Awesome code but how to i make it so it goes to the right page? All that happens is that it comes up with a blank page.
dj_jonathan_martin [anti-spam] yahoo.com March 26, 2007
Thanks so much for this great script!

Having a bit of a problem though, when I run the help execution to get the path, I get a local c:\ path ... any advice would be appreciated! Thanks again :)
dj_jonathan_martin [anti-spam] yahoo.com March 28, 2007
nevermind that was the absolute file path on the server. WORKS GREAT!! THANK YOU !!!
exentia [anti-spam] cooltoad.com April 1, 2007
Thank you very much
spented half a day trying htaccess
no luck
happened upon your site googling
15 minuites later all working
as my 5year old says "wicked"
Vivian April 4, 2007
Thanks! This is exactly what I was looking for.

One thing though, it doesn't seem to work in Mozilla Firefox. When I click the link it should show the password page, but it just skips that step. It only worked once in the beginning, but that was it.

Any suggestions on why it's not working?
April 6, 2007
Nicholas

AWESOME SCRIPT. THANKS A TON!!!!
phani April 10, 2007
Thank you very much
michelle [anti-spam] NOSPAM [anti-spam] lwmarina.biz April 12, 2007
Ok.. For the folks that want a password protected page and have NO IDEA how to install anything at all..

If I install(haha ya right) this on a single page, like a private page on my site, do people have the same login's and password.. just give all the people the same id and password??
philwojo April 13, 2007
Vivian, it sounds like you are forgetting about the cookie it sets, you will only see it work once as after you log in it set's your cookie's and then it' won't run again.

Michelle, you set the login's and passwords in the file, so you can put in as few or as many as you want to, or you can give everyone the same one.

Phil
Gregorio Aristizábal April 15, 2007
Excelent work!!! Got my password script working in no time! Really easy to use and straightforward. Works well on GoDaddy, with Mozilla.

Could not use the htaccess method due to hosting restrictions, but the script does a great job. You just saved me from having to do it from scratch! Thanks again man.

Take care!

PS. Agree with shawn on the comment "I've tried to edit the cookie portion out of the script to no avail. I would like the script to always require the user to provide a username and password. Some way to easily comment out or disable this feature."
dazakun [anti-spam] shaw.ca April 18, 2007
Awesome script! Thanks! I got it working very quickly with the helpful forum instructions.

One question I have is if it is possible after implementing the login/password form (user has to input both fields) on the main page of a website, to have it redirect to another page on the website after successful authentication. Thanks again
Wesley April 19, 2007
Great script! I modified it slightly to create an online proofing system. It redirects clients to their respective directory depending on the credentials they provide! Thanks again!
Hugh April 20, 2007
Very nice bit of work. Kudos! I have added two functions:-

- javascript to automatically select the pasword box (I disabled the username for my pages); and
- created a setting to show hide the hyperlink to your website - I didn't want to make it too easy for anyone to know how I was securing my pages - the less the bad guys know the better!

But very nice work.

Regards


Hughdesmo
foo April 22, 2007
I changed the passwords in the script but whenever i try to login with the username/passwords i added i get Incorrect password.
pula April 25, 2007
Great script! keep up the good work.
AJ April 25, 2007
Wesley,

I am interested in doing a similar thing - would i be able to see your modifications / source?

Many Thanks,

Folder April 25, 2007
AJ, check the forum, there are multiple threads about redirect after login. Brgds, Folder
Ben April 27, 2007
First, great script!
Al lot of people are asking about changing the usernames and passwords from the default.

Make sure you make the changes in the script and not in the instructions!!!

- Ben
DaveyDee April 28, 2007
SUPERB!
I've been googling to find a solid, easy to depoly password script for a few days now and thank goodness I found Zubrag. You are a star my friend - this script is so simple yet so effective. Take a gold star and go to the top of the class!
Kory May 9, 2007
Great script!! I love it!!

My only question is if the script can be made to reflect on different users; for example: if "Bob" logs in then I want it to show "Bob's" page. Or if "Fred" logs in, then I want it to show "Fred's" page.
Thanks!!
AJ May 9, 2007
@ KORY:

go to the forums. zubrag, some others and myself have got that covered (you just add:

$REDIRECTS = array (
'username1' => 'PATH_TO_PERSONAL_PAGE',
'username2' => 'PATH_TO_PERSONAL_PAGE'
);

etc etc

underneath 'login details' in the password_protect script
May 11, 2007
how do I redirect back to the login page after someone clicks logout by using the passwordProtectedsite.php?logout=1

HERE IS THE CODE FROM PASSWORD_PROTECT.PHP

// logout?
if(isset($_GET['logout'])) {
setcookie("verify", '', $timeout, '/'); // clear password;
exit("Logged Out");
}
Kory May 12, 2007
Thanks AJ! But, the script fails to redirect to a php page, all it does is redirect to the root of the site when it's set to redirect to thefile.php. But, it does work with HTML files, unfortunely those don't let me set up protection on them, only the php files let me do that. I am stuck. Any suggestions??
Kory May 13, 2007
Update to previous post:

I finally figured it out!
I am doing a HTML post to password_protect.php file, it leaves a cookie if the password is good, it then redirects to another php file that is set to be secured with password_protect_2.php which has the same usernames and passwords but does not make the file redirect. This work-around works great!! I hope that may help somebody with the same problem! Thanks again!!!
jesstankersley [anti-spam] gmail.com May 13, 2007
This was awesome! Works like a charm! Thank you!!!!!
joe [anti-spam] salesdepartment.com May 15, 2007
I installed this several months ago on a phpbb 2.19 board. Since the day it was installed the board has not had one single spam registration. Pretty phenominal! I was getting near 10 spammers a day before installing this script.

And, another minor miracle I picked up somewhere particularly for those of you with phpbb boards. Rename admin_db_utilities.php with some off-the-wall name. Do the same with your admin_forums.php file. Rename admin_forums.php correctly "only" when you need to admin your forums. Then rename it something non-functional when you're done. No hackers since using this process.
carl [anti-spam] dltlive.com May 17, 2007
This is how I get mine to redirect to the orginal login page. In my password_protect.php this is what this area looks like:
// logout?
if(isset($_GET['logout'])) {
setcookie("verify", '', $timeout, '/'); // clear password;
header("location:http://url.to.redirect.to.com");
exit;
}
It may not be exactly what people are looking for but it works for me. Hope this helps. Good luck!
tom_cai12 [anti-spam] hotmail.com May 21, 2007
This is awsome!

I am new in php. Is there easy way to process contents based on the password in the same page? for example, if password = "external" , process function1 elseif password = "internal" process function2?

Thanks.
Tom
May 23, 2007
Wonderful! Thank you so much for sharing this...
May 23, 2007
Web Page Password Protect rocks. I had it set up in under 5 minutes and it did exactly what I wanted it to.
Daniel K May 23, 2007
to: Kory
I've been stuck same place as you, is it possible you could upload/send the work-around?
Kory May 25, 2007
In response to the question from Daniel K:

[Admin note] created topic on the forum for this issue: Password Protector - redirects
May 27, 2007
No problem installing. Easy to use. Thanks Hansen Denmark.
JT May 31, 2007
Great script, much appreciated Zubrag
June 9, 2007
this script is fantastic! very nice work.
kdhawkins [anti-spam] gmail.com June 12, 2007
I know nothing about HTML really, I can cut and paste and fiure stuff out generally, but reading all of this giving me a headache, plus I'm using MS Publisher 2003... OF all that has been mentioned, could you tell me how to set up a password protected page where each member can use their email address as their login and choose their own password? I want to put this on my own website (yahoo), but I'm really trying it out for another (university) website in the fall. Any help that you can give me is VERY appreciated!

Thanks so much!

K
Aa June 12, 2007
I tryed to paste the code into "nvu" and then open it but any password works. How do I set the password?
melissa June 14, 2007
Is there any way to create a "logout" with this password protect?
Craig June 15, 2007
Love the script man. Works a charm. The only i suggest, is a log out feature, more secure. But still a great job!
Ben June 16, 2007
Works great. Thanks for the log out feature too!
June 17, 2007
404 errer what the umm how do i fix it it was on a freewebs page
houssam.ballout [anti-spam] gmail.com June 20, 2007
Hello all,
I've included the file in the files that I want,but when I lunch them,the login form is not shown
any help please
June 26, 2007
Excellent script, worked like a charm. Thanks very much! :)
Dave H June 26, 2007
Great script! Unfortunately the cookie does not seem to be working as I have to enter the password again when I browse to another protected page in the same directory
pga June 26, 2007
well, im using this for my schools website but i want to style it so that it fits better. how do i do this?
Sasa June 27, 2007
ok i just got the script, its perfect, but, one question, i am password ptrotecting a proxy page, protection page is awsome, as soon as i go to a diffrent page through proxy, sets me back to log in., any help appreciated
jim June 28, 2007
Fantastic script. Even for a PHP newbie, really easy to use. Thanks
droom June 29, 2007
Thnx for script. Im very new in php but it took 10 minutes to understand how to use it. Really thank you
scott June 30, 2007
does anyone know how to echo the current user?
pat [anti-spam] organizedwisdom.com June 30, 2007
Another fan of this script! Thank you.
July 7, 2007
This rocks. Thank you!
Jordan July 8, 2007
I love your script but there needs to be a log out function when the user closes the browser. What if the user is on a public computer? A logout option will be very useful, and needed.
July 14, 2007
Great working script with full details on instructions...however, I'm having 1 minor blurp...once I enter the password and hit 'submit' it goes to (renamed file = login.php) login.php...can this be changed to a html file?
support [anti-spam] giggigteam.zzn.com July 21, 2007
g8 script but can u set up a form and when its filled out it automaticly adds username and password so they can login
marek4 [anti-spam] ya.ru July 30, 2007
Ìîëîäöû ïðåêðàñíûé ñêðèïò
BuB August 4, 2007
So Easy, and So Darn nice. GREAT Work. Love the cookie thingy, and how it times out instantly when they shut down the browser and come back.
EXCELLENT. THANKS
monin12001 [anti-spam] hotmail.com August 4, 2007
I am getting this
Warning: Cannot modify header information - headers already sent by (output started at /data/web/virtuals/.........

Line refers to the cookies portion...
just like marsha told...

i want cookies but dont want that error msg.. any help
Thank u
Monika
RTP August 4, 2007
nice script. thanks
Brother T August 6, 2007
Zubrag,
How would you do this? I want to
1 - have the login form open in a smaller window (target="_blank")
2 - have the small window close after login info is accepted while
3 - updating the original window to reveal the protected site content.
JohnnyF August 9, 2007
For some reason, when I enter the URL www.mysite.com/password_protect.php?help - it gives a dialogue box asking me if I want to open or save the password_protect.php file. I'm pretty sure this is a server issue. Has anyone got any ideas?
August 9, 2007
does this program offer user logging?
Lozza August 9, 2007
I'm adding in the code at the top of the script like it says - but when I go to the secure.php file on the site it doesn't load up the login fields. Any thoughts?!
August 9, 2007
Excellent. Nice of you to post your work for free. Well done!
daybroadway [anti-spam] yahoo.com August 10, 2007
I am having a problem with the login on my php login page. I created a login page where users can login into the site and access other php pages on the site. I put the php protect password on the pages desired. the problem i am having is when the user goes to the login page and logs in it says it's successful but when they go to the protected pages it asks them to login again.
Mick August 14, 2007
This is a fantastic script, exactly what I wanted, thanks!
Hendy88 [anti-spam] gmail.com August 16, 2007
The code works GREAT! Just one problem, in that after the user logs in from my index.php page, they get redirected to another page telling them they are logged in and everything works great. Problem is if (within the same browser session), they stray away from these PHP pages and then come back to the original index.php page... instead of showing the content, it shows and "Index of" and a listing of the files in the Parent Directory on the server. Any suggestions on how to fix this?
Tracy August 17, 2007
Fabulous piece of code! I couldn't get .htaccess/.htpasswd to work, so I was looking for another solution. This is exactly what I needed! Thanks!
August 18, 2007
I am using this script but the google adsense ad not relative to content on password protected pages.They ask to give password protected directory/file & authentication URl then waht is to be written in authentication URl ?
koisti August 21, 2007
I'm using only password protection so not user name needed. The password should be an email address, so have to add check to submit that it even looks like an email address like xxx.xx@xx.xx?
And the password can be anything..
so if you hit correct password it goes works like original but if you try give email address withous @ mark it gives an error message not a valid email address
Gang Zhou August 23, 2007
Excellent! Very easy to use and very convenient!
Guillermo August 23, 2007
I've put it to work in just a minute!!! Thanks a lot!
Anne August 27, 2007
Thank you, thank you! Brilliant piece of code!! I'd spent hours trying others - noe of which worked. Yours was super-quick to install and worked immediately.
Shadow Slash August 28, 2007
Ohhhhh i'm so jealous! I wanna try that stuff now! It's just a shame that my website's server is currently down so I can't try uploading the password_protect.php thingy T_T
kevin [anti-spam] plessinger.net August 28, 2007
Perfect worked like a charm. You rock!
E-man August 30, 2007
VERY Cool! Simple, easy and it gets the job done unlike others I have tried with line after line of extra junk code. Thanks for such a great code.
Renee September 13, 2007
Thanx heaps!! Got it working straight up! Saved me heaps of time. Cheers ;)
greg September 13, 2007
great code! agreed to password protect a site without knowing how to do it. this makes me look good. ;-)
Dave Clarke September 13, 2007
Hi,
I am not very good at php, adn wa wondering if you could show me how to edit the script so it checks mysql db for the user and password rather than a preset one!
waldir September 18, 2007
I would like to have a form for registration on my site, where user would inform login and password, and they would have automatic access to the protected directory. How could I do it? Thanks.
badgirl September 19, 2007
Thank you so very much for writing this script and for making it so easy that even I could understand it. It worked perfectly, and I am using GoDaddy. I was even able to put it right into a the look and feel of my website. And my site uses CSS. If anybody needs help with getting it to work for them, just let me know. If I can do this...anybody can do it. :-) zubrag you totally rock!
soojan September 19, 2007
that's grt man... it worked fine ! thanx dude.
ncarrier [anti-spam] hotmail.co.uk September 21, 2007
This did not work for me :( spend ages on this and it still would not work followed every step buy no luck
Eduardo September 22, 2007
Muito obrigado pelo script! Será muito útil para o meu site. Obrigado amigo!

Thank you for this script! It will very useful to my site. Thank you friend!
September 26, 2007
This is an awesome script. I can't thank you enough for creating it!!!
amber September 26, 2007
my boy chris from akron gave me the web site and forgot to give me the password can i get it though
October 1, 2007
Very Nice!!! Thanks!!!
October 10, 2007
Hi Zubrag.
Is it possible to rename the html pahaes to php to be able to use this script?
bram October 10, 2007
is there a way to use the forms with a 'GET' method and not 'POST' because I have another script on that page and in won't work if there is another form with a post method on that page :s
rs-knights [anti-spam] hotmail.co.uk October 14, 2007
i'm having problems trying to add more users could you give me an template/example? of 2 users

Thanks-
Ray
Jaffa Designs October 15, 2007
This is a great script that is easily integrated into full HTML/CSS sites. Well written and easy to understand...Thanks Z - Jaffa Designs (Australia) http://www.unaking.com/password_protect.php
asta October 15, 2007
Zubrag,
How do I do this (similar to earlier post):
- make access to protected web page transparent to reader of an eBook ie. the reader just clicks the hyperlink ona eBookpage referencing external protected URL, withour having to, enter user id or passwords!

Reason is to prevent accidental stumblers onto my webpage but allow book readers to access via hyperlink, without requiring them to enter the password.

Can the password be auto-supplied forexample,maybe likeso:

http://pw@www.example.com

so that reader doesn't have to be bothered by it?
asta October 15, 2007
I found the answer digging in the forum. Awesome script. Thanks......
AC October 15, 2007
Great Script, thank you for sharing it and being so helpful.
October 17, 2007
Can this script be used as a registration option, so that when users come to my site they can register themselves, get a username and password and then login into the site, instead of me having to create a username and password everytime. This is a super script which is why i'm asking if more functionality can be added.
julian October 22, 2007
hi,
id like to set up the password within a box in my site. im using iweb, so its simple to add the login script as a box in the page (i.e. my home page) but once a user enters their details, id like the page to open in a new tab or window. how do i do this? so what id need is code to tell this to open in a new window once login is complete...i can simply add the page with the generated code into the page.. should be easy i think!
Demortes October 23, 2007
Excellent addon to protect my osCommerce admin tool. I love it so much, you are a genius. Saved me the time to learn this type of stuff. I just included it in the header file that is used all the time in the administration tool.
Bob October 24, 2007
fantastic add-on took less than an hour to reconfigure and password protect the admin area. Cheers!
October 26, 2007
this doesnt work it display tons of junk and im really mad
October 31, 2007
when the page refreshes it again asked for username password...
kalobaharon [anti-spam] yahoo.com November 6, 2007
please i don't understand it properly thank may God bless u.
Robert November 8, 2007
Hallo!

Grate script thank.
Is it possible to make chackbox to decide weather to use cookies or not. This will be great function for me.
benjus [anti-spam] alice.it November 10, 2007
Hi... first of all: sorry for my bad english! (i'm italian) i've tried this script but it doesn't work...i upload the php file, then open the help section... i login and when i press the button to enter, it appears a blank page... why? help, please!
benjus [anti-spam] alice.it November 10, 2007
Now i've solved the first problem, i've obtained the php include string... the problem is that even if i put the string on the top of the page code, the login for doesn't appear... and i don't know why
Raine November 14, 2007
Hey! I figured out how to create a link to previous page on a subdirectory and you can enter back to your password protected page without logging in. It's easy to do with javascript.

<A HREF="javascript:javascript:history.go(-1)">Previous Page</A>

Note: this will only work if had you previously logged in, as script remembers password until browser is closed.
lol November 19, 2007
epic fail.
JT November 25, 2007
I'm trying to get the Web Page Password Protect script to work for me. I've followed your instructions and had it going on the first try, but messed up at some point. So started over. Now, every time I get this error message on the page I'm protecting after inputting my specified user name and password: "Warning: Cannot modify header information - headers already sent by (output started at /home/content/d/o/r/dorjecontem/html/Download.php:3) in /home/content/d/o/r/dorjecontem/html/password_protect.php on line 137
What's gone wrong? I simply can't repeat my initial success (which I botched by trying to style the password protect input page to more closely match my site). Thanks. I'm soooooo close!
November 25, 2007
For me scripts don't work
frankie.soliz [anti-spam] yahoo.com November 29, 2007
can i watch tonights game?
bachi November 30, 2007
hi can any body tell me what is the password for this script?

thank you
bachi November 30, 2007
if we upload all our php files in to our server. then how the browser onen our site with out asking the p/w. and i want any body open my site and i dont want to give the permission to save or print my web pages.. can any body suggest for this?
December 3, 2007
looks nice but doesn't work. didn't have time to figure out why, but needs some work. tried it with php and html doc. just goes to protected page with now username or password page. let us know when its fixed. would like to try it. thanks
flash December 3, 2007
i've tested this script every which way an it fails miserably, as has about 75% of the scripts that I test on the net. When you type ...password_protect.php?help, you do not get a valid output for one. Too many errors to list here.
Brian December 3, 2007
script does work with firefox. include

error_reporting(0);

That will suppress the errors coming through and make it so you can put it before the content of a page in the include so when the right password and login has been entered you can then see the rest of the content.
Davo December 4, 2007
Disregard flash's comments. I have uploaded password protect on my website and have it working nicely.(even with firefox) Thanks to everyones help on the forums I have tailored the code to suit my site.
baboo December 4, 2007
Works great for me! Verified in IE, Firefox, and Opera.
'flash' why don't you post a topic on the forum? They will help you to get it setup correctly.
December 14, 2007
Works great! Thanks!
December 20, 2007
Love this program. Thanks.
tuaans [anti-spam] gmail.com December 23, 2007
thanks you.
besi [anti-spam] mailbox.co.za December 29, 2007
i would like to try this but is having plain text passwords on a script safe at all? why are passwords not in msql database and encrypted?
Jill January 4, 2008
LOVES IT! THANKS SO MUCH!!!!! WORKS LIKE A DREAM!
noemail [anti-spam] hotmail.com January 4, 2008
many thanks!
January 6, 2008
the password and id # doesnt work
January 6, 2008
the password and id # doesnt work
Banning January 8, 2008
this script is hot and works 100% i've been using it for awhile now... i pull all my stuff from a database... if you need help on connecting this script to a database just run a search on this page for mysql or database and up towards the top in 2006 zubrag was kind enough to help a fellow out with connecting it to a database and that code has work perfectly for me.
hawkeye0386 [anti-spam] gmail.com January 14, 2008
The script works great! But where I work, they want some form of a logout button. I just don't know how to code it to work with the script. I can get it to close the window, but then it doesn't delete the cookie.

HELP!!!
Orlando January 14, 2008
Do you have codes that may be added in html files to be protected? i'm using html codes in my page. Where in this site can i find such, if any..
rohen22 [anti-spam] gmail.com January 14, 2008
Awesome script! I'm trying to use it as a redirect, so far so good!!! Thanks!
ivo [anti-spam] paximadia.com January 15, 2008
I do not want a user/password combination, but just a password. According to the description, I would need to change the user/password combination to just a password (starting from line 51). But if I do, I keep getting two fields to fill out, instead of one. Anyone any ideas what I could be doing wrong? Other than that, great script and thanks to the very clear explanation also customizable for a non PHP-person like me!
ivo [anti-spam] paximadia.com January 15, 2008
Sorry, after I submitted my previous comment, I saw that there is also a forum. And there it was explained: in line 58, change 'true' to 'false'.
Ali January 16, 2008
This was exactly what I was looking for , but I am having a lil problem; The cookie doesn't seem to work. I have cookies enabled so I am wondering what I am doing wrong. as it is I am required to log into each page I navigate too. Are there any other settings I need to put in?
Hartmut January 16, 2008
I love it. Simple and effective.
You made my day.
SleepinDevil January 20, 2008
You guys do realize this script is very primitive and very insecure.. Also its almost 2 years old now... Since you all use PHP head on over to www.php.net and read the online documentation for SESSION_START() and learn how to use PHP Sessions. They are much more secure and much more versatile!
-Ragnarok Server PHP & Database Admin
Gerard January 21, 2008
Great script , thanks for sharing.
big_djg [anti-spam] yahoo.com January 21, 2008
i need sum help with setting up the password on my webpage... im reading wat to do but i dont get it to well. Can someone please help me my email:is Big_djg@yahoo.com
dave January 23, 2008
include("' . str_replace('\\','\\\\',__FILE__) . '"); ?&gt;');

That doesn't look anything like what everyone else put up... solutions?
rchamberst2 [anti-spam] hotmail.com January 23, 2008
I am trying to password protect a webpage. I am using frontpage 2003 can I use this code and if so how?
NELSON January 23, 2008
THE SITE IS REALLY VERY USEFUL
saif_phy [anti-spam] yahoo.com January 24, 2008
This code is fine but password is case senstive. How can I make it otherwise
January 29, 2008
Thanks for this. Fantastic.
azrobert [anti-spam] cox.net January 30, 2008
Having Problems getting include line

saved password_protect.php to server but hwen i enter the path and /password_protect.php?help

It comes up with a login box and won't recognize my passwords or users


??
January 30, 2008
I have found the solution to the logout not working with the back button. Re direct it to a blank page that contains a link with the Javascript code (<a href="javascript:window.close();">You Must Click Here to Finish Logging Out!!!!! </a>) to force browser to close. This is a simple way to remind people to close the browser
denroy [anti-spam] activeice.co.za January 30, 2008
Hey, this is a great script,but i have a bit of a problem. all my username and password are stored in an database and although i am linking to the database correctly i cant get into the desired page.

all my user deatails fails to log me in correctly
Patel January 31, 2008
Hi Zubrag,

Great script. Just what I have been looking for.

I am trying to redirect the page in the event there is an invalid login/pwd to the original page I place the login and pwd. How would I go about doing that? I am able to redirect to the right page if the login/pwd is correct. I tried below code and did not work:

if ($check == "Ok"){
header('Location: http://localhost/containertrucking/websitex/menu.html'); die();
else
header('Location: http://localhost/containertrucking/websitex/index.html'); die();
}

Thanks in advance for your help.
Paige February 1, 2008
I love the script! It works perfectly. The only question I have is, can you customize it? By that I mean change the colors of the log in interface? (eg. background, box color, font, etc)? And if so how could I do that?
February 3, 2008
Hi,

I tried the script and after a few modifications and tries, it worked great !


Just my thought though, wouldn't it be better, instead of redirecting user to an embedded html inside the php, to just ask them using a javascript?
john [anti-spam] cleanexpo.com.au February 6, 2008
The script works fine - thanks - but how do I set it to log out? At present if they move to other page son the web site they can just re-enter the password protected page and it is not until the browser is shut down entirely does it then prompt for the password again.
vishalgaurav01 [anti-spam] gmail.com February 18, 2008
Yeah, Good Script,

Thanks,
Vishal
vishalgaurav01@gmail.com
http://vishal.benetonfilms.com
tes February 18, 2008
great script! thanks!
jonnovello [anti-spam] yahoo. com February 18, 2008
So, how secure is this script? I have a client who wants a password protected page that allows users to download his software. It would be nice to know that what I'm using for him is basically secure.

Thanks!
j
johnstell [anti-spam] interstellar-solutions.co.uk February 20, 2008
hi,
Great script - works easy - just one thing though - not sure how to protect a second page when a user fills in a form on the first page and then is redirected to a second page?

What code do you have to use again on the second page - it isn't quite clear?
patelgasagency [anti-spam] gmail.com February 20, 2008
Big Hello,
thanks for the work done by the pioners of this site and the way the work has expanded in the grounds back home. will like to appriciate the work done by all of you for us and the community to be rooted to the ground and trying to bring the feeling of togtherness and unite the people of entire samaj.
s-barrick [anti-spam] suddenlink.net February 21, 2008
Hi,

Will this php script work on a Windows IIS server? That is where my site is that I would like to add this script. I know nothing about programming, but this script looks like it is just what I'm looking for...

Thanks,
Sarahb
Artix February 22, 2008
Who can help?
Some one is inserting his index.html in mai webpage...and i have changed my password..i-m using an php script...if someone can help me it whould be nice...
brandonc503 [anti-spam] yahoo.com February 25, 2008
Hey, great work btw. I am trying to get the user name from cookie but seems to be encrypted, which is great, but how would i go about decrypting it. thanks.
February 26, 2008
Great Script!!! you saved me from putting too uch time into doing it myself. Just a question If I front end the pages I wish to password protect with this, I should be able to specify session variables pulled from the mysql db and propagate them to the page being protected, that way the app can carry a variable on the server side such as username that can be populated to the protected pages.
February 26, 2008
It is not working for me. Can anyone help? I put the script under test folder and created a simple html page and included one liner. I am hosting at godaddy.

thanks,

ro
clabinger [anti-spam] sbcglobal.net March 3, 2008
Is there a way to use this script to prevent access to other files (such as images) by people who have not entered the password? OR: To prevent viewing of subdirectories on the website (Index of /folder)?

Thanks in advance.
March 4, 2008
is it free
uvex_ [anti-spam] hotmail.com March 4, 2008
Can u add a function, so that we can change the password, without editing the code??
March 6, 2008
<QUOTE>jonnovello [anti-spam] yahoo. com February 18, 2008
So, how secure is this script? I have a client who wants a password protected page that allows users to download his software. It would be nice to know that what I'm using for him is basically secure.
Thanks!
j</QUOTE>

I have the same concern. Everything I have read says that simple password scripts are not really secure and are easy to by pass or obtain passwords.
How secure is this program? Does it really protect personal information contained in the protected page?
karl [anti-spam] nilsen.as March 12, 2008
Thanks for a nice script.
Just what I needed, password for reading the internal sites.

Thougt of contribution info - i would have contributed!

karl@nilsen.as
grahamson.1 [anti-spam] hotmail.co.uk March 13, 2008
hi and i am fron sctland and i am finding it really hard..

wat i am trying to find out is how can i make a box saying pass and a box saying uuser name and submit. and when u get the pass right u go to anuther page.. ?

please some one help me
Antispam March 14, 2008
PERFECT!
Thanks a lot!
Pola March 16, 2008
This worked like a champ.Cannot be enough thankful to you.Great work.
infoATflutelab.com March 16, 2008
The script could not be opened in MSIE or FF. So how can I resolve the code to paste? Maarten
ScrumpsNet March 17, 2008
Very cool Script!!
Thanks for posting.

Question:
With some Usernames and Passwords combinations after login I need to re-direct them to another page. How would you implement script like that into your current code structure?
March 20, 2008
This is a dumb website it doesnt work at all
Kerry March 24, 2008
Using it to protect my live xampp server root.

Thanks a bunch :-)
rajibhossan [anti-spam] yahoo.com March 25, 2008
I need advance php tutorial
bachanal [anti-spam] ntlworld.com March 25, 2008
Thank you, thank you, thank you! I am a designer struggling with coding and "programming" stuff! Would you believe that after days of searching the web, your script was the ONLY one I understood and could use! I am so grateful! I have registered with your forums for the future. Great - Diana
March 25, 2008
Thanks sooooooooo much for this I have been playing around with .htaccess this little script is fanatstic
March 25, 2008
wonderful script - works perfectly - and I've never used php before - well done! V grateful!!!
ursus [anti-spam] giterental.com March 28, 2008
Excellent script, easy to set up and works well. Thankyou. Ursus the Bear.
Sena March 30, 2008
Thank you so much!!!! It works perfectly :)
KarlKaluns March 30, 2008
How good is this script? Is it "hackable"?
Sam March 30, 2008
I have a way of making it work in html
Just put
<iframe src="the/path/to/password_protect.php"></iframe>
Sam March 30, 2008
EDIT : the HTML can only do this if the path was like
http://www.yoursite.com/the/path/to/password_protect.php
and not a root path
JFD March 31, 2008
To those who were asking how to always require login, just change the timeout minutes to an extremely small value (ie .001).
Rick April 1, 2008
I am using the login and password name fields to access a protected web page. If I add a wrong login(username), password or both and press "submit", I get a display of "Incorrect password". Is any way to improve the code so that if I add a wrong user name but correct password, it displays "incorrect login(username)" or if I add a correct login(username) and a wrong password, it dislays "incorrect password" and if I add a incorrect login(username) and a incorrect password, it displays "incorrect login(username) and password". I tried to manipulate the code but failed to get it working.
alexandernewman19 [anti-spam] comcast.net April 7, 2008
I need some help, I haven't the slightest idea on how to do this, I get the form on LOGIN and Password, but I don't know how to set the information for it. When I do I get 3 errors, would some one help me step by step, php codes are my weakest area in coding things and building webspage thats why I stick HTML.
reckylawalata [anti-spam] yahoo.com April 9, 2008
script yang hebat dan luar biasa. sangat membantu dalam aplikasi yang saya buat untuk kantor kami. terima kasih dan Tuhan memberkati
Jakoma April 10, 2008
Im using freewebs for my website and i just wondered wjere to put the script
and also i cant get the code
spawnkornfreak [anti-spam] yahoo.com April 14, 2008
great work!!!
but how to add the users login name to my page?
for example i want to add their login name right after the logout button... also is there a way that we could add a visitors log?
silentgaia [anti-spam] gmail.com April 16, 2008
for some reason, when i paste the php code onto the page i want to protect, it wouldnt work. Can anyone please help me? I've done everything.
rmist April 16, 2008
silentgaia, is the page you are trying to protect a .html file or a .php? It should be a php file. Also is the php code pointing to the correct place where the script is? If the password_protect.php file is in the same directory as the web page you are protecting, you can just put the path as password_protect.php

Hope that helps
April 17, 2008
Thanks !!!! I really apreciate a lot this script.
novoshare [anti-spam] gmail.com April 17, 2008
Thanks !!.
I have found more in two interesting sources ( http://filesfinds.com & http://fileshunt.com ) and would like to give the benefit of my experience to you.
April 19, 2008
1 million thank yous!!!
Christian April 19, 2008
hello!

I tried this script, but doesn't work for me, help please :(!

http://www.redlatinoamericana.com/web/intranet.php
harismol [anti-spam] pollux.gr April 19, 2008
u saved my weekend with this great script. Thank you very much
etaxero [anti-spam] gmail.com April 21, 2008
This script worked AMAZINGLY well... I am learning php and this helped me out so much!
croz April 21, 2008
wont work for me, getting message "A file permissions error has occurred. Please check the permissions on the script and the directory it is in and try again."

Any ideas? I am pretty sure my directory is correct
admin [anti-spam] arperture.com April 22, 2008
<a href="http://sphider.arperture.com">Arperture Search</a> uses this script. :)
April 22, 2008
This is great! I was having so many issues with security - and this will take care of it. Thanks so much!
jm April 26, 2008
I LOVE IT
meliej April 27, 2008
you are incredible! this script is great and i really, really appreciate you sharing it, especially for free!
general [anti-spam] benbaxter.co.uk April 27, 2008
Hi,

I've placed the pass protect php file on the server and added the code to the top of the php file I want to protect - but when I link to the latter it goes straight to it without asking for any login details?

What am I doing wrong?
badinfluencedj [anti-spam] hotmail.com April 30, 2008
hi zubrag..Great script..just wondering if i could pick ya brain,as im having a bit of trouble...i uploaded the script to one site for testing.and it worked great.not problems at all..but as i copyed the folder and pasted to new site..it seems to have gone wront..

i made sure i delete the note directory folders that are always created.but i reckon i have missed somethink....the error message i get is___
e:\domains\d\dnbupload.com\user\htdocs\upload\samples\login\login.php on line 67

if you could help that wood be great..look forward to hearing from you..and thanks a heap for the scrip..ITS PROPERRR..
Caelan May 4, 2008
I was wondering if you could include a demo on this page so that I (and others) could see it in action before I download it.

Thanks :)
Nisho May 4, 2008
This code is ******* amazing... im speechless. But i keep getting this error:

Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\index.php:8) in C:\wamp\www\password.php on line 141

I have tried to read some of the 1000 of comments above, and i have tryied to include that line of code at the begenning of the document, but it didnt work out, i think im doing something wrong... can you help me guys?
Thanks alot...
Nisho May 4, 2008
Ah i just added the // (comments) on line 141... and it has stopped showing that. but im just wondering if it would cause a problem ? i havent really gone through the code and im not that advanced in php yet, so if someone could tell me what does that line do and if its problematic to remove that line. the line is:

setcookie("verify", md5($login.'%'.$pass), $timeout, '/');
sergeyp [anti-spam] mac.com May 6, 2008
Great script, I must be having a problem each time i go between pages that are protected or want to refresh, it forces me to log in again. Is this a problem with the cookies?
Matt May 7, 2008
wow, amazing, works a treat, THANK YOU.
Dan May 9, 2008
thanks a lot thats was what i was looking for >< , its easy to use and usefull
andrew [anti-spam] aeonianrock.com May 9, 2008
hey sweet script man. Quick question. How can I determine the user name that is logged in? I have users who will submit a news post, and i want to insert the user id of the person logged in that is posting. It appears you are hashing the user with the password. This would be great if you could help.

Add Comment

!!! Comments posted here will not be answered. If you want to ask a question please post it on the forum.

E-mail or Name: Not required. Email will be protected from spammers

Comment: Please do not post unrelated comments

Anti-spam: Please enter (2fa6b752) into the box