Code: Select all
<?php
class mudAuth
{
protected $username;
protected $password;
protected $additionalinfo;
protected $authtype;
function set_info($username, $password, $additional = array())
{
$this->username = $username;
$this->password = $password;
$this->additionalinfo = $additional;
}
function set_auth_type($type)
{
$class = $type . 'Auth';
if (class_exists($class)) {
$this->authtype = new $class;
}
else {
trigger_error('There is not such a type of authorization supplied by this class.<br />Available are: DB, TXT, HTTP, XML', E_USER_WARNING);
exit;
}
}
function check_info()
{
return $this->authtype->control();
}
}
class DBAuth extends mudAuth
{
protected function control()
{
$controlarray = array("hostname", "username", "password", "databasename", "tablename", "usernamecolumn", "passwordcolumn");
foreach ($controlarray as $celement)
{
if (!array_key_exists($celement, $this->additionalinfo)) {
trigger_error('A required information for this authorization type is not given: <span style="color:red;">'. $celement .'</span>', E_USER_WARNING);
exit;
}
}
@mysql_connect($this->additionalinfo['hostname'], $this->additionalinfo['username'], $this->additionalinfo['password']) or trigger_error('Connection to MySQL aborted. Reason: '. mysql_error(), E_USER_WARNING);
@mysql_select_db($this->additionalinfo['databasename']) or trigger_error('Database selection aborted. Reason: '. mysql_error(), E_USER_WARNING);
$query = @mysql_query("SELECT * FROM ". $this->additionalinfo['tablename'] ." WHERE ". $this->additionalinfo['usernamecolumn'] ." = '". $this->username ."' AND ". $this->additionalinfo['passwordcolumn'] ." = '". $this->password ."'");
if (mysql_num_rows($query) > 0) {
return true;
}
else {
return false;
}
}
}
?>Code: Select all
Warning: array_key_exists() їfunction.array-key-exists]: The second argument should be either an array or an object in c:\wamp\www\test\mudAuth.php on line 43
Warning: A required information for this authorization type is not given: hostname in c:\wamp\www\test\mudAuth.php on line 44