Questo il codice di index.php3
- Codice: Seleziona tutto
<?
include "BasicAuthenticator.php";
$realm = "My Secret Pages";
$errorMessage = "Private. Keep Out!";
$auth = new BasicAuthenticator($realm, $errorMessage);
// Define a set of valid usernames and passwords.
$auth->addUser("test", "test");
$auth->addUser("user", "pass");
// And now perform the authentication
$auth->authenticate();?>
<HTML>
<body>
Prova
</body>
</HTML>
Questo il codice di BasicAuthenticator.php
- Codice: Seleziona tutto
<?
// PHP BasicAuthenticator Class Version 1.3 (24th March 2001)
//
// Copyright David Wilkinson 2001. All Rights reserved.
//
// This software may be used, modified and distributed freely
// providing this copyright notice remains intact at the head
// of the file.
//
// This software is freeware. The author accepts no liability for
// any loss or damages whatsoever incurred directly or indirectly
// from the use of this script. The author of this software makes
// no claims as to its fitness for any purpose whatsoever. If you
// wish to use this software you should first satisfy yourself that
// it meets your requirements.
//
// URL: http://www.cascade.org.uk/software/php/auth/
// Email: davidw@cascade.org.uk
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 $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;
}
}
?>
Mi potete aiutare?
Grazie