"; 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 $PHP_AUTH_USER; global $PHP_AUTH_PW; if ($this->authenticated < 0) { if(isset($PHP_AUTH_USER)) { $this->authenticated = $this->validate($PHP_AUTH_USER, $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; } } ?>