Zubrag.com
March 28, 2017, 05:55:44 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1] 2 3 ... 5
  Print  
Author Topic: Password Protection example  (Read 391676 times)
zubrag
Administrator
Hero Member
*****
Posts: 785


WWW
« 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 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
- adding logout link
- password protect pdf, doc, ppt, etc.
- Advanced Password Protect - supports signup, password reminder, redirect after login, header/footer templates and more
- Password protect HTML

Logged
psp
Newbie
*
Posts: 5


« Reply #1 on: June 29, 2007, 12:12:50 AM »

thank you.
Very simple and easy to understand...great script Cheesy
Logged
badgirl
Newbie
*
Posts: 4


« Reply #2 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! Cheesy
Logged
jon novello
Newbie
*
Posts: 2


« Reply #3 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
Logged
sarahb
Newbie
*
Posts: 1


« Reply #4 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
Logged
xtianbraun
Newbie
*
Posts: 1


« Reply #5 on: April 19, 2008, 07:36:39 AM »

Hello everyone!

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

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

Can anyone help me? Thanks!
Logged
laquintain
Newbie
*
Posts: 1


« Reply #6 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.
Logged
tejaswi1506
Newbie
*
Posts: 1


« Reply #7 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
Logged
PhilippeT
Newbie
*
Posts: 1


« Reply #8 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
Logged
jenmca
Newbie
*
Posts: 1


« Reply #9 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
Logged
eitsfan
Newbie
*
Posts: 1


« Reply #10 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
Logged
fluorescente
Newbie
*
Posts: 2


« Reply #11 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
Logged
fluorescente
Newbie
*
Posts: 2


« Reply #12 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
Logged
-dhi-
Newbie
*
Posts: 1


« Reply #13 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
Logged
Pages: [1] 2 3 ... 5
  Print  
 
Jump to:  

Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC