|
Posted by FP on 07/18/06 04:34
Rik wrote:
> FP wrote:
> > I want to put some code at the top of my pages which will prompt the
> > user for a name & password if the session variable IDUser is not set.
> >
> > How do I get the browser to display the login / password dialog and
> > how do I access the data the user entered.
>
> http://www.php.net/manual/en/features.http-auth.php
>
> Grtz,
> --
> Rik Wasmus
I had a look at the manual and it's clear as mud.
Tomorrow I'm going to try to put the following code in an include and
call it from the different pages; it's currently working with 1 page.
If anyone sees potential problems with it, could you please point them
out.
if ($_SESSION['IDUser']=='') {
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm="Demo"');
header('HTTP/1.0 401 Unauthorized');
exit;
}
//connect to database searching for record where
Login = $_SERVER['PHP_AUTH_USER'];
Pwd = $_SERVER['PHP_AUTH_PW'];
if(no records found){
header('WWW-Authenticate: Basic realm="Demo"');
header('HTTP/1.0 401 Unauthorized');
}else{
$_SESSION['IDUser'] = database record ID
}
}
Navigation:
[Reply to this message]
|