Getting a password

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
datruter
Forum Newbie
Posts: 2
Joined: Wed Jan 31, 2007 8:28 am

Getting a password

Post by datruter »

Hi everyone,

I need help on password protected directories on a server?
If I created a password protected directory and added users with their own passwords, is there any way that I can see who logged in and submitted data on the forms within the directory.

OR

How can I create a username and password form for all the pages within a directory so that each user must login before making use of the forms or pages. I do not want anybody to be able to access the forms only registered users.

Thank you all
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You can write PHP scripts that require log ins similar to the password protected directory stuff.

header() may be of interest along with http://php.net/features.http-auth
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

Post by dibyendrah »

Htaccess may be your interest to do your work.

http://en.wikipedia.org/wiki/Htaccess
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

Post by dibyendrah »

Taken from users note just for a sample.

Code: Select all

<?php

function auth_user() {
   $realm = mt_rand( 1, 1000000000 );
   header('WWW-Authenticate: Basic realm="Realm ID='.$realm.']"');
   header('HTTP/1.0 401 Unauthorized');
   die("Unauthorized access forbidden!");
}

if (!isset($_SERVER['PHP_AUTH_USER'])) {
   auth_user();
} else if (!isset($_SERVER['PHP_AUTH_USER'])) {
   auth_user();
} else if ($_SERVER['PHP_AUTH_USER'] != $auser || $_SERVER['PHP_AUTH_PW'] != $apass) {
   auth_user();
} else if (isset($_GET['action']) && $_GET['action'] == "logout") {
   auth_user();
}

....
?>
datruter
Forum Newbie
Posts: 2
Joined: Wed Jan 31, 2007 8:28 am

Got it...

Post by datruter »

Thanks for the replies,

So if I got it right I need to unprotect my directory and
write a php user login file that gives access to all the files
on the directory?

Thanks again
Post Reply