incollo qui tutto il codice... magari non è dove penso io l'errore...

class BasicAuthenticator
{
var $realm = "<private>";
var $message;
var $authenticated = -1;
var $users;

function BasicAuthenticator($realm, $message = "Access Denied")
{
$this->realm = $realm;
$this->message = $message;
}


function authenticate()
{
if ($this->isAuthenticated() == 0)
{
Header("HTTP/1.0 401 Unauthorized");
Header("WWW-Authenticate: Basic realm=\"$this->realm\"");
echo $this->message;
exit();
}
else
{
Header("HTTP/1.0 200 OK");
}
}


function addUser($user, $passwd)
{
$this->users[$user] = $passwd;
}


function isAuthenticated()
{
//global $_SERVER['PHP_AUTH_USER'];
//global $_SERVER['PHP_AUTH_PW'];

if ($this->authenticated < 0)
{
if(isset($_SERVER['PHP_AUTH_USER']))
{
$this->authenticated = $this->validate($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
}
else
{
$this->authenticated = 0;
}
}

return $this->authenticated;
}


function validate($user, $passwd)
{
if (strlen(trim($user)) > 0 && strlen(trim($passwd)) > 0)
{
// Both $user and $password are non-zero length
if (isset($this->users[$user]) && $this->users[$user] == $passwd)
{
return 1;
}
}
return 0;
}
}