Zubrag.com :: Forum

zubrag.com => Password Protect => Topic started by: zubrag on December 14, 2006, 09:03:22 AM



Title: Password Protection example
Post by: zubrag on December 14, 2006, 09:03:22 AM
A lot of requests for more detailed description on how to setup password protector. Will do my best to clarify.

Download password protector (http://www.zubrag.com/scripts/password-protect.php) to your local computer.

Unzip files from downloaded zip archive. You'll get password_protect.php.

Open password_protect.php in your favorite editor. You'll see following section inside:

Code:
##################################################################
#  SETTINGS START
##################################################################

// Add login/password pairs below, like described above
// NOTE: all rows except last must have comma "," at the end of line
$LOGIN_INFORMATION = array(
  'zubrag' => 'root',
  'admin' => 'adminpass'
);

// request login? true - show login and password boxes, false - password box only
define('USE_USERNAME', true);

// User will be redirected to this page after logout
define('LOGOUT_URL', 'http://www.example.com/');

// time out after NN minutes of inactivity. Set to 0 to not timeout
define('TIMEOUT_MINUTES', 0);

// This parameter is only useful when TIMEOUT_MINUTES is not zero
// true - timeout time from last activity, false - timeout time from login
define('TIMEOUT_CHECK_ACTIVITY', true);

##################################################################
#  SETTINGS END
##################################################################

Update this section according to your needs. You can add/delete users in this section.
By default it is setup to grant access for two users:

User: zubrag
Password: root

User: admin
Password: adminpass

After you updated settings, save password_protect.php somewhere on your hosting server.
Lets say your website address is http://www.haveahobby.com, and you saved password_protect.php in /htdocs/protector/ folder

Open your browser, and type your site URL + path to the password_protect.php?help
In our example it would be: http://www.haveahobby.com/protector/password_protect.php?help

It will output something like
<?php include("/home/haveahobby/htdocs/protector/password_protect.php"); ?>
This output is a protection code which needs to be added to every php file you want to protect.

Lets say you want to protect your existing file named members.php.

You open members.php in your favorite editor, and add protection code at the very beginning of the file.

Lets say before update your members.php was:
Code:
<?php
echo "This information needs to be secured. Members area. Only members should be able to access it";
....
?>

After update it would look like (we added protection code at the beginning):
Code:
<?php include("/home/haveahobby/htdocs/protector/password_protect.php"); ?>
<?php
echo "This information needs to be secured. Members area. Only members should be able to access it";
....
?>

We secured members.php.

Now open your members.php file in browser. It should show login/password prompt.

Add protection string to every php file you want to protect.


Tip: if you want to protect html file, and your hosting supports php, then you can rename your html file into php file, and use password_protect.php as described above.

For example you want to protect sensitive-info.html.
Rename it to sensitive-info.php, and follow steps above.

Related links:
- implementing login form into site design (http://www.zubrag.com/forum/index.php?topic=94.0)
- adding logout link (http://www.zubrag.com/forum/index.php?topic=202.0)
- password protect pdf, doc, ppt, etc. (http://www.zubrag.com/forum/index.php/topic,182.0.html)
- Advanced Password Protect - supports signup, password reminder, redirect after login, header/footer templates and more (http://www.zubrag.com/scripts/password-protect-advanced.php)
- Password protect HTML (http://www.zubrag.com/tools/html-password-protector-encoder.php)


Title: Re: Password Protection example
Post by: psp on June 29, 2007, 12:12:50 AM
thank you.
Very simple and easy to understand...great script :D


Title: Re: Password Protection example
Post by: badgirl on September 18, 2007, 11:35:02 PM
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! :D


Title: Re: Password Protection example
Post by: jon novello on February 18, 2008, 12:37:36 PM
This looks great, but I'm curious -- how secure is this?  I have a client that wants a password protected page linked from his website, where he can direct users to go to and download his software.  I don't think he needs it to be super duper secure, but knowing that it's basically not all that hackable would be nice.

Thanks.

j


Title: Re: Password Protection example
Post by: sarahb on February 21, 2008, 03:02:48 PM
Hi,

Will this password protect php script work on a Windows IIS server?  That's were my site is located.  The script looks perfect, but I know nothing about programming so wondered if I will have any problem placing it on this type of server.

Thanks,
Sarahb


Title: Re: Password Protection example
Post by: xtianbraun on April 19, 2008, 07:36:39 AM
Hello everyone!

I tried this, but it doesn't work for me...  :(

http://www.redlatinoamericana.com/web/intranet.php

Can anyone help me? Thanks!


Title: Re: Password Protection example
Post by: laquintain on April 25, 2008, 04:16:22 PM
hello i was wondering if i could yous this for yahoo geocites?I have the free version and i want to pasword protect my blog.I was wondering how i can use this to block people from my blog.


Title: Re: Password Protection example
Post by: tejaswi1506 on May 16, 2008, 08:42:13 AM
i am not able to dis.some gateway error is coming after doing                         
"Update this section according to your needs. You can add/delete users in this section.
By default it is setup to grant access for two users:

User: zubrag
Password: root

User: admin
Password: adminpass

After you updated settings, save password_protect.php somewhere on your hosting server.
Lets say your website address is http://www.haveahobby.com, and you saved password_protect.php in /htdocs/protector/ folder

Open your browser, and type your site URL + path to the password_protect.php?help
In our example it would be: http://www.haveahobby.com/protector/password_protect.php?help" step.........................please help me........help me to make my site password enabled


Title: Re: Password Protection example
Post by: PhilippeT on May 20, 2008, 01:25:27 PM
500 phpwrapper internal error : ERR_MISSING_CGI_PRIVILEGE (45)

No matter what I do, I'm getting the above mentioned error.

Any Idea where it is coming from ?

http://users.skynet.be/Theunissen_Beniest/password_protect.php?help

Best regards


Title: Re: Password Protection example
Post by: jenmca on June 02, 2008, 12:48:55 PM
I have carefully followed all the instructions on how to get the password protect script working but when I enter the address of the protected page it comes right up, the password is not required to see the page.  Could I be missing something? I put the password_protect.php file on my server, changed the username and password and added the line of code needed to protect the page to the very first line like required. Any ideas?

Jennifer


Title: Re: Password Protection example
Post by: eitsfan on June 03, 2008, 06:37:16 AM
I'm having the same problem as jenmca. I'm also no expert at this so I'm probably doing something wrong, but I can't figure it out! Any help would be gratly appreciated!

Chris


Title: Re: Password Protection example
Post by: fluorescente on June 21, 2008, 10:59:53 AM
Thank you very much
It works nicely but I try to connect it to a database with no success
You told on the comments we should change this:

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

I made the connection to the database the dreamweaver way (recordset) and it seemed to work. Anyway my site is only password, no user&pass, so I changed your code into:

$LOGIN_INFORMATION = array();
while ($row = mysql_fetch_assoc($result)) {
$LOGIN_INFORMATION[$row['USERNAME-FIELD-NAME']];
}

All with the names from my site, but it doesn't work.
What can be? Please help me
My code after other try was:

$LOGIN_INFORMATION = array();
do {
   $LOGIN_INFORMATION[$row_contras['pass']];
    } while ($row_contras = mysql_fetch_assoc($contras));

It didn't work either...
I left it like this:

$LOGIN_INFORMATION = $row_contras;

It only takes the first password from the table of my database.. so I only have one available password by the moment, since I don't know what more to try in order to it takes all the passwords from the table

Thank you VERY much


Title: Re: Password Protection example
Post by: fluorescente on June 21, 2008, 12:27:10 PM
Ok! I didn't read properly.
I had to put the password name from the form and the row name from the database

$LOGIN_INFORMATION = array();
do {
   $LOGIN_INFORMATION[$row_contras['access_password']] = $row_contras['pass'];
    } while ($row_contras = mysql_fetch_assoc($contras));


Anyway it doesn't work. Now it only takes the last value from the database

I tried this:
$LOGIN_INFORMATION = array();
for($i=0; $i<$totalRows_contras; $i++){
   $LOGIN_INFORMATION[$row_contras['access_password']] = $row_contras['pass'];
}


And it only takes the first value. I hope you can help me to understand it
Thanks
What happens? Thanks


Title: Re: Password Protection example
Post by: -dhi- on July 08, 2008, 01:24:47 PM
Hi!
I follow your instructions but it didn't want to work!
I have this error:
"Warning: Cannot modify header information - headers already sent by (output started at /var/www/save.php:9) in /var/www/protector/password_protect_page.php on line 165"

what does it mean?
I really don't know what to do!
Please help me
Thank you!

Sorry
I didn't read your post about it, now I don't get any problem with that warning
but, I still have another problem, I put "save.php" (the one that I want to protect) on the root folder, and put my "password_protect_page.php" on the protector folder.
But then, when I tried to open the save.php, there's nothing on that page, BLANK.
what does it mean?
please, help me
thanks


Title: Re: Password Protection example
Post by: alexrox127 on July 09, 2008, 10:17:24 PM
On my page i want to password protect i put in the code the script provided me with and it says "Warning: include(public_html/admin/password_protect.php) [function.include]: failed to open stream: No such file or directory in /home/a7539236/public_html/admin/index.php on line 1"

"Warning: include(public_html/admin/password_protect.php) [function.include]: failed to open stream: No such file or directory in /home/a7539236/public_html/admin/index.php on line 1"

"Warning: include() [function.include]: Failed opening 'public_html/admin/password_protect.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/a7539236/public_html/admin/index.php on line 1"

What do i do?


Title: Re: Password Protection example
Post by: kws on July 14, 2008, 06:48:01 AM
Hi, great script. Think i have it working ok.

But can i get the form for the login details to appear on my site.
Basically i want to put that section of code on one of my template pages so it looks the same as the rest of my site.

Can anyone help with this, Thanks.


Title: Re: Password Protection example
Post by: kws on July 15, 2008, 03:11:32 AM
Hi, ive got the script up and running with my website background but now im having a problem with the log in, everytime i go to a new page it keeps requests the log in.

I have no time out currently set so i dont see why this should happen.
Can you help me out please. Thanks


Title: Re: Password Protection example
Post by: kws on July 15, 2008, 09:32:55 AM
Ok Never mind my last 2 posts ive, managed to figure it out and as a far as i can tell i have everything up and running.
Although the support wasnt great i cant complain as the code is really handy.
Thanks for the .php code.


Title: Re: Password Protection example
Post by: annann on July 25, 2008, 05:16:40 PM
Thanks for the scripts. It works. And it's easier than I thought!
I just have one more question. Is there anyway I can track who have been logged in? (by the users name I have assigned to them).
Please advise.  Thanks so much! =)


Title: Re: Password Protection example
Post by: zoipes on September 04, 2008, 06:43:52 PM
I uploaded the password protect script. The passwords provided do not work. After I type them in, I get "incorect password". Any idea what is wrong?


Title: Re: Password Protection example
Post by: bellskees on November 17, 2008, 05:05:33 AM
Hi There,

I am trying to protect a page or pages (html) on a website.
I do not use php & am not familiar with it.

Can someone tell me what I need to do to password protect pages?

Do I need to install PHP?

Many thanks,
 ???


Title: Re: Password Protection example
Post by: dgow on December 01, 2008, 11:31:22 PM
I am also having the same problen as jenmca.  I followed the instructions... then put a link on one of my pages to the secure page. When I click on the link to go to the secure page i get the login page just like i am suppose to. After inputting the id & password it takes me to my secure page.  BUT, if I type the url of the secure page directly into the address bar then the secure page comes up with out any login to get to it. Not really secure to me.  Any suggestions?


Title: Re: Password Protection example
Post by: Lyle on January 27, 2009, 12:54:49 PM
Is there a way for users to change their own password? 

Is there a way to issue a user a temporary password and then they set their own?




Title: Re: Password Protection example
Post by: recoding on February 09, 2009, 03:19:23 PM
Is there a way for users to change their own password? 

Is there a way to issue a user a temporary password and then they set their own?



Offhand no, you would need a fully featured content management system for that kind of thing, you would need levels so that you as the admin could remove/change passwords, and users could only change their own..when you start thinking like that its complicated.


Title: Re: Password Protection example
Post by: recoding on February 09, 2009, 03:21:48 PM
I have carefully followed all the instructions on how to get the password protect script working but when I enter the address of the protected page it comes right up, the password is not required to see the page.  Could I be missing something? I put the password_protect.php file on my server, changed the username and password and added the line of code needed to protect the page to the very first line like required. Any ideas?

Jennifer
I am also having the same problen as jenmca.  I followed the instructions... then put a link on one of my pages to the secure page. When I click on the link to go to the secure page i get the login page just like i am suppose to. After inputting the id & password it takes me to my secure page.  BUT, if I type the url of the secure page directly into the address bar then the secure page comes up with out any login to get to it. Not really secure to me.  Any suggestions?

Hey you two (:

Basically, once you've logged in once, your logged in until you close your browser/ a hour...this works whatever way you go to the website..

Basically once you've logged in its like you actually have the keys to the house, not just been let in the door, you have access to the pages for a period of time, not just for that one time you logged in. I hope this helps.


Title: Re: Password Protection example
Post by: stevo on February 27, 2009, 01:01:12 PM
Can anyone help me with a problem I'm having getting the script to work?

I've used it on one site with no problems (and it's brilliant!) but when I try the same code on another site (different server) I get the following message at the top of my protected page:

Warning: Cannot modify header information - headers already sent ... in password_protect.php on line 137

...and after that, any action I try and do on the page keeps sending me back to the login screen.

Can anyone help? I'm really struggling to figure out what's happening!

Steven


Title: Re: Password Protection example
Post by: recoding on February 27, 2009, 06:21:46 PM
You need to have <?php include 'password_protect.php'; ?> at the VERY top, if there is even one space, or one blank line it wont work.


Title: Re: Password Protection example
Post by: ostatni on March 12, 2009, 09:43:53 AM
And I get:
Parse error: parse error in C:\inetpub\wwwroot\Password\password_protect.php on line 116

even if i do not touch to password_protect.php file
and cannot go anyfurther..
could somebody help


Title: Re: Password Protection example
Post by: recoding on March 12, 2009, 09:52:08 AM
Hi ostatni,
Could you please copy and paste into a reply lines 115, 116 and 117?

Should be able to start to help then.


Title: Re: Password Protection example
Post by: pan2 on March 22, 2009, 09:02:37 AM
Hello,
I've been working on this for countless hours now, to the point that I think I'm about to cry.

As with so many other people, I've encountered the incredibly bothersome "cannot modify headers" problem:
Warning: Cannot modify header information - headers already sent by (output started at /home/doki/public_html/hetalia/admin2.php:1) in /home/doki/public_html/hetalia/password_protect.php on line 184

I've already checked for white spaces and there aren't any. I wonder if it's because I'm trying to combine so many different scripts and I have no idea what I'm doing. admin2.php is supposed to have a password form and then upon entering the correct password, it opens and displays another text file (which I have working).

These are the first two lines of admin2.php
Code:
<?php include("/home/doki/public_html/hetalia/password_protect.php");
include (
'pagestop.txt'); //regular text file with header info like <html>..<body>
//below this is code for opening & displaying another .txt

This was originally line 184 of password_protect.php, and after I // out the line as I read under the comments on the main page, the line of error changed to 158.
Code:
setcookie("verify", md5($lp), $timeout, '/');

These are lines 157-158 of password_protect.php
Code:
// set cookie if password was validated
    setcookie("verify", md5($login.'%'.$pass), $timeout, '/');
After I commented out line 158, the headers problem disappeared. But then, naturally, it wouldn't remember any cookies and I would have to re-enter the password each time which is tiresome!

Please help, somebody! I can also email my entire PHP codes and also give the URL to show the problem.


Title: Re: Password Protection example
Post by: recoding on March 23, 2009, 12:46:20 PM
Hi pan2,
It sometimes can be hard to read the errors, the error is basically saying that the command on line 158 cannot be ran because of: output started at /home/doki/public_html/hetalia/admin2.php:1 or basically, admin2.php seems to have something on line one..what do you use to edit your files? try opening in wordpad(windows) or textedit(for mac) and making sure there is absolutely nothing there, if it still doesn't work send me a private message with the two php scripts attached, and I'll try and have a look for you.


Title: Re: Password Protection example
Post by: pan2 on March 23, 2009, 08:23:52 PM
I use notepad, and I've checked time and time again! I am certain there are no white spaces!
I will send you the PM now though, thank you for helping!


Title: Re: Password Protection example
Post by: nairda on April 06, 2009, 03:15:03 PM
Hello,

This script seems fantastic and is just the thing I'm looking for, however I've the same problems as many others and have been trying to fix for many hours now! Have searched all the postings but no luck I'm afraid. I've added the line <?php include("/mounted-storage/home61b/sub009/sc38678-FRKH/cheaponlinetraintickets.co.uk/protector/password_protect.php"); ?> to my header.php file so gets added to all pages on the site. The problems I have are:

1) Warning: Cannot modify header information - headers already sent by (output started at /mounted-storage/home61b/sub009/sc38678-FRKH/cheaponlinetraintickets.co.uk/wp-content/themes/cheap-online-train-tickets-theme/three_column_template_cheap_tickets.php:7) in /mounted-storage/home61b/sub009/sc38678-FRKH/cheaponlinetraintickets.co.uk/protector/password_protect.php on line 137

If I comment out the line 137 this message is gone :-) But I would like it to have the option for cookies, how can I do this? I've checked my documents and can't see any white space.

2) I have to login on every page! I only want to enter the login details once so I can then browse all of the website.

This is a test site (need to implement this on a live site once I have ready). Any help would be much appreciated. I'd gladly email you the password_protect.php and header.php files I am using if it helps.

Kind regards,

Adrian


Title: Re: Password Protection example
Post by: recoding on April 06, 2009, 03:20:13 PM
Hi Adrian,
The problems 2 and 3 are because of 1, cookies make it possible to save that you have logged in, and delete them when you logout.

So to do anything, we need to fix problem 1, now just commenting it out does fix the problem, but removes complete functionality.

Basically you may have added the password_protect to the right place, however the file ../wp-content/themes/cheap-online-train-tickets-theme/three_column_template_cheap_tickets.php loads BEFORE header.php so that is the problem, to be exact on the file three_column_template_cheap_tickets.php on line 7, something is said, what I recommend is moving the line:
Code:
<?php include("/mounted-storage/home61b/sub009/sc38678-FRKH/cheaponlinetraintickets.co.uk/protector/password_protect.php"); ?>
and adding it to three_column_template_cheap_tickets.php on line one. It should work then.


Title: Re: Password Protection example
Post by: nairda on April 06, 2009, 03:38:53 PM
Hello again,

It's always the way isn't it, you search for hours to find a solution before making a posting... then a few minutes later find the solution :-) http://www.zubrag.com/forum/index.php/topic,360.0.html made it very clear what was needed to fix my problems.

Tried to delete my previous post but couldn't see how so just wanted to say a big thank you for the script :-)

Many thanks,

Adrian


Title: Re: Password Protection example
Post by: recoding on April 06, 2009, 03:43:14 PM
Ah I thought you may have read that, okay :D


Title: Re: Password Protection example
Post by: lambofgod on May 05, 2009, 09:14:06 PM
Hi, i'm so newb at this its not even funny.

Where would i set my username/password?

I see a line where it say's

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

and i tired to replace
 'root' with my username &
'adminpass' with my password.

it still wouldn't let me log in :( please help!!!


Title: Re: Password Protection example
Post by: recoding on May 06, 2009, 04:56:15 AM
Hey lambofgod,

Could you private message me your complete script (the whole file) I'll take a look (:


Title: Re: Password Protection example
Post by: designer on May 10, 2009, 01:58:32 AM
Hello-
I have been trying for hours now to get the password to take in my file and I can't get it to take, and let me in to what I am protecting.

Would someone have some advice?



Title: Re: Password Protection example
Post by: recoding on May 10, 2009, 02:54:43 PM
Take in your file? how are you including it? If you do not want to paste your code here please feel free to PM me and I'll try my best to help out ;)


Title: Re: Password Protection example
Post by: akishimo on May 16, 2009, 03:01:51 AM
lambofgod:
you're supposed to replace 'zubrag' with username and 'root' with password. Same for the next line.

For all those who couldn't get the log-in page to come up, I had the same problem until I discovered this:

Let's say you were trying to password protect "Home.html".

You change the name to "Home.php"

However this "homepage" comes with a folder that contains your images and other stuff.

The password log-in may not be showing because you probably have to change everything in your folder that used to refer to "Home.html" to "Home.php"

I created an entirely new test page with no other folders/files attached, and the password script worked perfectly.

Hope this helps.


Title: Re: Password Protection example
Post by: maco on May 29, 2009, 10:01:46 AM
Is there a way to add a logout button at the page that has been protected and when the user presses it it sends them back to the login page... I know when the session times out this happens but I want the user to be able to do it aswell...

how would this be done?


Title: Re: Password Protection example
Post by: recoding on May 29, 2009, 03:51:43 PM
Is there a way to add a logout button at the page that has been protected and when the user presses it it sends them back to the login page... I know when the session times out this happens but I want the user to be able to do it aswell...

how would this be done?

Include this code wherever you want the logout button to appear:
Code:
<form method="get" action="(enter your php document here).php?logout" /><input type="submit" value="Logout" /></form>


Title: Re: Password Protection example
Post by: peaces on May 30, 2009, 09:20:00 AM
Hi recoding,

You seem to really be helping a lot of people with password protect. Thanks!

I just downloaded it and set it up with no issue and it works great in protecting the .php page I need protected.

I have added the script you have given above to a location on the .php page.

I also changed ="(enter your php document here).php? to ="mcleland.php?.

mcleland.php is the name of the protected page. When I click on the logout button, it just returns me back to the mcleland page.

Should I have put something else in for the (enter your php document here)?

Thanks in advance.


Title: Re: Password Protection example
Post by: recoding on May 31, 2009, 08:51:20 AM
Ah, I put the incorrect link, replace action="mcleland.php?logout" with action="mcleland.php?logout=1" so the code should be (for you):
<form method="get" action="mcleland.php?logout=1" /><input type="submit" value="Logout" /></form>

Now, when a user hits logout, the protect scripts sends them to a separate web address, in the password protect php document you got from here, go to line 60, you should get something like this: define('LOGOUT_URL', 'http://www.example.com/'); just replace http://www.example.com/ with where-ever you would like to send the user.

Yea, the password protect has helped me a lot and I kinda know a lot about it, edited a lot etc, so I would be happy to help others working with it (:


-Dan!

PS on another note, read lines 16 and 17 of the code:
# Add following HTML code to your page where you want to have logout link
# <a href="http://www.example.com/path/to/protected/page.php?logout=1">Logout</a>


Title: Re: Password Protection example
Post by: peaces on May 31, 2009, 12:25:05 PM
Thanks so much for the help. I for some reason cannot get the "Submit" button to work. If I just use the Logout text, it works fine. If I add the submit button as you have given it to me I return to the protected page. As soon as I take the submit button out of the line, it works.

Thanks again!


Title: Re: Password Protection example
Post by: recoding on May 31, 2009, 02:00:56 PM
Ah, I wrote it wrong again, I'm replying to this from my phone, so please forgive me if this does not work this time either, try this code:
<form method="get" action="mcleland.php" /><input type="submit" value="Logout" /><input type="hidden" name="logout" value="1" /></form>


Title: Re: Password Protection example
Post by: swami on June 03, 2009, 10:10:17 PM
Hi there...

I have a couple of problems

problem #1
I am having trouble with entering new usernames and passwords other than the two examples that are listed.
  'zubrag' => 'root',
  'admin' => 'adminpass', //added the comma as directed
  'sam' => 'password'       

I cannot use the sam option, but the admin works.  When I changed the admin password to adminpass1, it did not work.

problem #2
In my editor, on the very first line, I posted:  <?php include("/home2/thecentu/public_html/password_protect.php"); ?>
This got rid of the error message, however, I cannot get the login page to reappear.  Did I goof somewhere?

Notes:
The page I want to password protect is html coded and saved as a php document.

Thanks!



Title: Re: Password Protection example
Post by: recoding on June 04, 2009, 02:46:46 AM
Hey there Swami, could you private message me your two documents? the password protected one, and the actual password-protect one and I'll look at your code for you, If you do not feel safe doing this, it is fine, I would just find it easier to diagnose your problem if I could see the complete code :)

-Dan!


Title: Re: Password Protection example
Post by: gokhul on June 16, 2009, 01:17:24 PM
Hi,

I dont have a php script in my code.
It is just a data entry page designed using html.
But the file was saved with the '.php' extension.
For such kind of files, can you tell me where to place the code?


Title: Re: Password Protection example
Post by: recoding on June 17, 2009, 05:12:56 AM
Hi,

I dont have a php script in my code.
It is just a data entry page designed using html.
But the file was saved with the '.php' extension.
For such kind of files, can you tell me where to place the code?
Hey there gokhul, I'm sorry but this will only work in PHP.


Title: Re: Password Protection example
Post by: gtswhitt on July 01, 2009, 08:43:56 PM
I can import just about anyone's website files with FrontPage.  Someone can do the same to me.  Can they also import the password_protect.php page that shows all of the passwords?  If so, is there any way to hide a file from downloading from the server to somebody else's computer?


Title: Re: Password Protection example
Post by: gtswhitt on July 01, 2009, 08:46:03 PM
Is there a way to add a logout button at the page that has been protected and when the user presses it it sends them back to the login page... I know when the session times out this happens but I want the user to be able to do it aswell...

how would this be done?

Include this code wherever you want the logout button to appear:
Code:
<form method="get" action="(enter your php document here).php?logout" /><input type="submit" value="Logout" /></form>


When I did this, anyone can figure out exactly where your password_protect.php file is located and go straight to it to download from your server with FrontPage, etc. can't they???????


Title: Re: Password Protection example
Post by: Leonel on July 23, 2009, 10:47:55 AM
I followed the instructions and it works great on all file but one.  On this particular file, edit.php,  the first line of code reads:

<?
$var = @$_REQUEST['cmd'] ;
//connect to mysql  

after I place the new line of code in, that I copied from the output of http:// ....com /protector/password_protect.php?  which returns
<?php include("/var/www/html/protector/password_protect.php"); ?>

I do get the login/password window when I try to access the edit file, after I enter the login the entire file comes up.  In that file, which is a membership directory, each name entry is individually editable. When I select to edit a particular entry, I once again get prompted for login/password, I enter the login again and then I get the following error message:

Error updating you: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

SQL: UPDATE directory SET name='',bio='',company='',biotitle='',email='',site='',title='',address='',city='',state='',zip='',phone='',vlink='',vname='',fax='' WHERE id=

If I remove the added code <?php include("/var/www/html/protector/password_protect.php"); ?> , everything works fine.  I tried a varied of different settings including adding php to <? tag or removing php from the added code ... but regardless of whatever I try, I can not get edit.php to function correctly unless I remove the added code.

Any suggestions?


Title: Re: Password Protection example
Post by: kerstey on August 12, 2009, 04:58:10 AM
Does this only work on Linux?

I have windows hosting and can't get it to work.  :'(

When I get to this point:

"After you updated settings, save password_protect.php somewhere on your hosting server.
Lets say your website address is http://www.haveahobby.com, and you saved password_protect.php in /htdocs/protector/ folder

Open your browser, and type your site URL + path to the password_protect.php?help
In our example it would be: http://www.haveahobby.com/protector/password_protect.php?help"

It just re-opens the password_protect.php code in explorer

help!!!



Title: Re: Password Protection example
Post by: recoding on August 12, 2009, 05:39:28 AM
Hmm depends what you mean by windows hosting. One form is a WAMP server (Windows, Apache, MySQL & PHP). Another form is with MSSQL, it uses a really bad scripting language called ASP. or ASP.Net. To find out if your server supports PHP, make a blank .php file (eg php.php) and in it write this:
Code:
<?php phpinfo(); ?>
If it comes out with lots of information, then PHP works, and the above script should work fine. Make sure you followed the instructions correctly :)

-Dan


Title: Re: Password Protection example
Post by: kerstey on August 12, 2009, 05:46:52 AM
no, it doesn't work. I think it does use ASP.

Bummer!


Title: Re: Password Protection example
Post by: luci_unikatu on August 27, 2009, 05:33:20 PM
Can you edit the script for me please ?  ???I wnt that the script to take the users from a txt file and to be a line for every user and his password  user_name:user_password (like in .htpasswd but without md5 encript  ;D) can ypou do this  for me ::) ?


Title: Re: Password Protection example
Post by: mkmcst on September 12, 2009, 04:02:47 PM
i have a stupid question  where would the  user name go in the script?

User: zubrag
Password: root

User: admin
Password: adminpass


Title: Re: Password Protection example
Post by: espdesignstudio on December 09, 2009, 12:22:33 PM
Thanks so much! I'm a total PHP noob, and after a few tries, I got it to work..... thanks so much! ;D


Title: Re: Password Protection example
Post by: saigopal on December 12, 2009, 12:04:26 AM
nice script


Title: Re: Password Protection example
Post by: lotuswoody on January 03, 2010, 09:12:33 AM
The script is exactly what I am looking for for multiple users but I am having a problem using it. I have followed the instructions but the generated protection script generated doesn't seem to run. I have changed it and now the password box appears on the page I am trying to protect.
What am I doing wrong?


Title: Re: Password Protection example
Post by: fr2632 on January 14, 2010, 12:41:11 PM
Hi Guys!

I created my page with files protected with only password :

// request login? true - show login and password boxes, false - password box only
define('USE_USERNAME', false);

but :

after digit the correct password I get after an empty page!!  ??? how do I redirect to another page? the protected page?

Thanks in advance!
Francesco.


Title: Re: Password Protection example
Post by: upod on January 20, 2010, 11:40:05 AM
I don't think the moderators look at the questions on this forum.

Is there anyone out there??... out there...out there...out there


Title: Re: Password Protection example
Post by: tomycat on March 07, 2010, 09:16:32 AM
How to create a flat file or
Can I use existing MySQL db?


Title: Re: Password Protection example
Post by: hodad77 on June 12, 2010, 06:30:05 PM
I got it working but it only works the first time one enters login/password. How do you disable cookies to prevent this from happening and have the info entered each time? Thanks in advance.