<?php
/**
* @author Mohammed Cherkaoui
* @link www.cherkaoui-php.com
* @copyright 2010
*/
class userChecker
{
/**
* Users table name
*
* @private string
*/
private $tableName;
/**
* Cookies names
*
* @private array
*/
private $cookiesNames = array('Username' => 'cookie_username','Password' => 'cookie_password');
/**
* Table columns names
*
* @private array
*/
private $columnsNames = array('Username' => 'column_username', 'Password' => 'column_password');
/**
* Array of the navigator rows
*
* @private array
*/
private $userinfo = array();
/**
* Language
*
* @private array
*/
// زائر = visitor > for the non-arabs ;)
private $Lang = array('visitor' => 'زائر');
/**
*
* Class constructor
*
*/
function userChecker($tableName = 'users', $columnsNames = array('Username' => 'column_username', 'Password' => 'column_password'), $cookiesNames = array('Username' => 'cookie_username','Password' => 'cookie_password'))
{
$this->tableName = $tableName;
$this->columnsNames = $columnsNames;
$this->cookiesNames = $cookiesNames;
$this->Check();
}
/**
*
* Start checking the navigator
*
*/
function Check()
{
$Check = $this->doCheck($this->getCookies());
if($Check == 0)
{
$this->userinfo = array($this->columnsNames['Username'] => $this->Lang['visitor'], 'usergroup' => 0);
} else
{
$this->userinfo = $Check;
$this->userinfo['usergroup'] = isset($Check['usergroup']) ? $Check['usergroup'] : 1;
}
}
/**
*
* Getting cookies according to the names in $cookiesNames var
*
*/
function getCookies()
{
return array('Username' => $_COOKIE[$this->cookiesNames['Username']], 'Password' => $_COOKIE[$this->cookiesNames['Password']]);
}
function doCheck($Cookies = array())
{
if(empty($Cookies['Username']) || empty($Cookies['Password']))
{
return 0;
} else
{
$userQuery = mysql_query("select * from ".$this->tableName." where
".$this->columnsNames['Username']." = '".mysql_real_escape_string($Cookies['Username'])."'
and ".$this->columnsNames['Password']." = '".mysql_real_escape_string($Cookies['Password'])."'
limit 1
") or die(mysql_error());
if(mysql_num_rows($userQuery) == 0)
{
return 0;
} else
{
return mysql_fetch_assoc($userQuery);
}
}
}
function userinfo($column)
{
return $this->userinfo[$column];
}
}
?>
|