Location: PHPKode > projects > MembersGear > membersgear/includes/banlist_class.php
<?php

 require_once "peardb_class.php";
    
 class banlist_class extends peardb_class
 {   
    function View($pQuery, $pValues=false, $types=true, $pStart=0, $pEnd=0)
    {
        /*
        global $mdb2;    
        $result;  
 
        $query      = 'SELECT * FROM tbluser1 t limit 10;';
        $resultset  = $mdb2->query($query);
        
        if(PEAR::isError($resultset)) 
        {
            die("Failed to issue query, error message : " . $resultset->getMessage());
        }
        
        while($row = $resultset->fetchRow(MDB2_FETCHMODE_ASSOC))
        {
            $result[] = $row;
        }
                                                                                                                 
        return  $result;   
        */
        //print_r($pParameters);
        
        return $this->BaseView($pQuery,$pValues,$types,$pStart,$pEnd);
        
    }
    
    function Update($pQuery, $pValues=false, $types=true)
    { 
       
        return $this->BaseUpdate($pQuery, $pValues, $types);
    
    }

    
    function Insert($pQuery, $pValues=false, $types=true)
    { 
    
        return $this->BaseInsert($pQuery, $pValues, $types);
    
    }
    
   function Delete($pQuery, $pValues=false, $types=true)
    {
        
      return $this->BaseDelete($pQuery, $pValues,null);
        
    }  
    
    function isBanned()
    {
                      
        if(!isset($_SESSION[SESSION_PREFIX.'banlist']))
        {
            $query = 'select * from '.TABLE_PREFIX.'banlist where isactive=1;';
            $larrBanlistRows =  $this->View($query);
            
            $_SESSION[SESSION_PREFIX.'banlist'] = $larrBanlistRows;
        }
        else if(!is_array($_SESSION[SESSION_PREFIX.'banlist']))
        {
            $query = 'select * from '.TABLE_PREFIX.'banlist where isactive=1;';
            $larrBanlistRows =  $this->View($query);
            
            $_SESSION[SESSION_PREFIX.'banlist'] = $larrBanlistRows;
            
        }
        else
        {
            $larrBanlistRows = (array) $_SESSION[SESSION_PREFIX.'banlist'];
        }
        //print "<pre>";
        //print_r($larrBanlistRows);
        //print "</pre>";
        //die;
        $larrBanlistCols;
        
        $lisRequestBanned = false;       // if banned request found then make this "true" and break the loop;
        
        $lRangFrom=0;                    // Ip Range starting from
        $lRangTo  =0;                    // Ip Range Ends To   
        $larrRang = array();
        
        $lsremoteaddress;
        
        if(is_array($larrBanlistRows) && sizeof($larrBanlistRows)>0)
        {
            foreach($larrBanlistRows as $key=>$value)
            {
                $larrBanlistCols = $value;
                
                
                switch ($larrBanlistCols['bantype'])
                {
                      case "1";  //ip address

                        if(strtolower(trim($larrBanlistCols['hostaddress'])) == $_SERVER['REMOTE_ADDR'])
                            {$lisRequestBanned = true;}
                        break;
                      
                      case "2";  // host name
                        if(strtolower(trim($larrBanlistCols['hostaddress'])) == strtolower(trim(gethostbyaddr($_SERVER['REMOTE_ADDR']))))
                            {$lisRequestBanned = true;}      
                        break;
                      
                      case 3;  // Ip Address Range
                        if(strpos($larrBanlistCols['hostaddress'],'To'))
                        {
                            $larrRang = split('To',$larrBanlistCols['hostaddress']);
                        
                            if(sizeof($larrRang) == 2 && is_array($larrRang))
                            {
                                $lRangFrom  = (double)str_replace('.','',trim($larrRang[0]));
                                $lRangTo    = (double)str_replace('.','',trim($larrRang[1]));
                                
                                if($lRangFrom != 0 && $lRangTo != 0)
                                {
                                     $lsremoteaddress =  str_replace('.','',$_SERVER['REMOTE_ADDR'])*1;
                                    
                                     if($lsremoteaddress >= $lRangFrom && $lsremoteaddress <= $lRangTo)
                                        {$lisRequestBanned = true;}      
                                        
                                     break;
                                }
                                
                                
                            }
                            
                        }
                        break;                    
                    
                }

                
                if($lisRequestBanned) break;
            }
        }

        
        return $lisRequestBanned;   

    }
    
 }   
 
/*
 require_once('../config/config.php');
 $t1 = microtime(); 
 
 $banlist_class = new banlist_class();
 
 echo $banlist_class->isBanned();
 
  
 //echo gethostbyaddr($_SERVER['REMOTE_ADDR']);
 $t2 = microtime();   
 
 echo $t2-$t1;
 */
 
?>
Return current item: MembersGear