PHP Classes
elePHPant
Icontem

File: userinfo.class.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Mohammed Cherkaoui  >  User-Checker  >  userinfo.class.php  >  Download  
File: userinfo.class.php
Role: Class source
Content type: text/plain
Description: the class
Class: User-Checker
Authenticate user with records in a MySQL database
Author: By
Last change: fixed, and sorry about the Errors !
Date: 4 years ago
Size: 3,332 bytes
 

Contents

Class file image Download
<?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
     */
     
     // &#1586;&#1575;&#1574;&#1585; = visitor > for the non-arabs ;)
     
    
private $Lang = array('visitor' => '&#1586;&#1575;&#1574;&#1585;');
    
    
   
/**
     *
    * 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];
    }
    
    
    
}


?>