Web Hosting Talk







View Full Version : HTTP Authentication with Ensim?


salamander
12-05-2002, 11:13 AM
Hi folks,

I'm trying to get HTTP Authentication working with PHP on an Ensim box - keep getting document contains no data errors.

The code i'm trying is this:

<?php

function authenticate ($realm="Secure Area" ,$errmsg="Please enter a username and password") {
header('WWW-Authenticate: Basic realm="$realm"');
header('HTTP/1.0 401 Unauthorized');
die($errmsg);
}

if (empty($PHP_AUTH_USER)) {
authenticate($realm,$errmsg,"header");
} else {
$query = "select * from users
where password = password(lower('$PHP_AUTH_PW'))
and username = lower('$PHP_AUTH_USER')
";
$result = safe_query($query);
if ($result) { $valid_user = mysql_fetch_array($result); }

if (!$result || empty($valid_user)) {
authenticate($realm,$errmsg,"query");
} else {
$isAdmin = $valid_user['isAdmin'];
}
}
?>



any ideas?

Rich2k
12-05-2002, 12:26 PM
What version of PHP are you using and is register_globals set to on?

As you should be using
$_SERVER['PHP_AUTH_USER']
and
$_SERVER['PHP_AUTH_PW']