Jump to content

authentication problem


dthomp325

Recommended Posts

I am using the PHP authentication system with usernames and passwords stored in a database. My code works just fine with Firefox, but with IE, I do not get authenticated. What am I doing wrong? Here is my login code:


<?php
session_start();
session_register('login');
session_register('username');
session_register('password');

#get login user and pass
if(!$HTTP_SESSION_VARS['login']){
$HTTP_SESSION_VARS['login'] = 1;
header('WWW-Authenticate: Basic realm="****"');
header('http/1.0 401 Unauthorized');
echo 'Login was not successful.
E-mail web master if problems persist.';
exit;
}

#check login with database
$auth = 0;
$user = $_SERVER['PHP_AUTH_USER'];
$pass = $_SERVER['PHP_AUTH_PW'];
if( isset($user) && isset($pass)){

#check user name and password in DB
require_once('DB.php');
$db=DB::connect("pgsql://wwwrun:wwwrun@localhost/***");
if(DB::isError($db)){ die("Login Error\n"); }

$sql = "SELECT count(*)
FROM users
WHERE username = '$user'
AND password = md5('$pass')
";
$r=$db->query($sql);
if(DB::isError($r)) die("Login Error\n");
$row = $r->fetchRow();
if($row[0] == 1){
$auth = 1;
$HTTP_SESSION_VARS['login'] = 1;
$HTTP_SESSION_VARS['username'] = $user;
$HTTP_SESSION_VARS['password'] = $pass;
}
}

#determine if login worked or not
if( !$auth ){
header('WWW-Authenticate: Basic realm="****"');
header('http/1.0 401 Unauthorized');
echo 'Login was not successful.
E-mail web master if problems persist.';
exit;
}
else{
header('Location: http://*****');
}
?>


When accessing this page, the authentication box pops up in IE, but after entering my login information, it spits out the 401/error message contained in the if(!$HTTP_SESSION_VARS['login']) statement.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.