Page 1 of 1

Getting a password

Posted: Wed Jan 31, 2007 8:49 am
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

Posted: Wed Jan 31, 2007 8:57 am
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

Posted: Wed Jan 31, 2007 10:50 am
by dibyendrah
Htaccess may be your interest to do your work.

http://en.wikipedia.org/wiki/Htaccess

Posted: Wed Jan 31, 2007 10:51 am
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();
}

....
?>

Got it...

Posted: Thu Feb 01, 2007 1:37 am
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