Solved

Creating a php session script with password required

Posted on 2009-07-14
8
381 Views
Last Modified: 2013-12-13
I have a site on which I want to limit access to the three of the pages to users who have the correct username and password. I would like a php script so that as soon as the user clicks on the navbar button for any one of those pages, he gets a prompt  that requires username and password. (In this case they will be the same for all authorized users, no database interaction required).

I would also like the php script to create a session so that the user will not have to re-enter the login when he goes to one of the other protected pages or returns to them.

Let's say that the 3 protected pages are: page2.html, page3.html, and page4.html.

I'll continue researching this online, but please give me as much as  you can, up to and including the whole script. I'm really not one of those people looking for you to do my coding. I always learn best when I have a working example in front of me to start with.

Thanks!

John


0
Comment
Question by:gabrielPennyback
  • 4
  • 4
8 Comments
 
LVL 6

Accepted Solution

by:
ou_dober earned 500 total points
ID: 24851600
I found this online.  Are you wanting to integrate authentication?  And if so, what type?

http://www.zubrag.com/scripts/password-protect.php

ou_dober
0
 
LVL 6

Assisted Solution

by:ou_dober
ou_dober earned 500 total points
ID: 24851629
Here is when you extend out to multiple users.

http://www.zubrag.com/scripts/password-protect-advanced.php

ou_dober
0
 
LVL 1

Author Comment

by:gabrielPennyback
ID: 24851795
Thanks ou_dober, I downloaded the first script. It says to set the username and password somewhere in the attached snippet, but I can't figure out where? Could you re-post the appropriate section of the code stting the username as "green" and thepassword as "blue"?

My best guess is that I set them here, and that the username is 'root' and the password is "adminpass'
'zubrag' => 'root',
 'admin' => 'adminpass'

But if that's correct why doesn't say this:
'username' => 'root',
 'password' => 'adminpass'

???


Thanks, John

##################################################################
#  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
##################################################################

Open in new window

0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 6

Expert Comment

by:ou_dober
ID: 24918886
gabrielPennyback,

Did the information I provide help you find a solution?

ou_dober
0
 
LVL 1

Author Comment

by:gabrielPennyback
ID: 24918935
The only thing I need to know is where I set the username and password. Right now all I need is one username and password for everyone using the site.

John
0
 
LVL 6

Assisted Solution

by:ou_dober
ou_dober earned 500 total points
ID: 24919034
'zubrag' => 'root',

'zubrag' is the userid

'root' is the password for the zubrag account

Change them to what ever you wish and you should be good to go. Remove line 9 where the admin account is to reduce access to one account.  When ready to add accounts, just copy the line below and replace the username and password.  Also, if you only use on line, make sure to remove the comma or it will error out.  When adding accounts make sure to read the comma.  As for why,  That is just the way they wrote it.

Hope this helps.

ou_dober

 'zubrag' => 'root',

Open in new window

0
 
LVL 1

Author Comment

by:gabrielPennyback
ID: 24920506
That clears it up and now I can see the logic of it. Thanks!


0
 
LVL 1

Author Closing Comment

by:gabrielPennyback
ID: 31603343
Thanks again.

- John
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Creating Functions in phpMyAdmin 8 26
How to obtain the string from a PHP StdObject ? 6 33
PHP Curl to output a url 7 47
Delete  php pages of a part of our site 8 31
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question