IPAccess::__array2int PHP Method

__array2int() private method

private __array2int ( $p_IPAddressArray )
    private function __array2int($p_IPAddressArray)
    {
        if (!is_array($p_IPAddressArray) || sizeof($p_IPAddressArray) < 4) {
            return null;
        }
        $IPAddress = 0;
        for ($i = 0; $i < 4; $i++) {
            $IPAddress += $p_IPAddressArray[$i] * pow(256, 3 - $i);
        }
        return $IPAddress;
    }

Usage Example

Example #1
0
 public static function GetUsersHavingIP($p_ipAddress)
 {
     global $g_ado_db;
     $cacheService = \Zend_Registry::get('container')->getService('newscoop.cache');
     $cacheKey = $cacheService->getCacheKey(array('GetUsersHavingIP', $p_ipAddress), 'users');
     if ($cacheService->contains($cacheKey)) {
         $users = $cacheService->fetch($cacheKey);
     } else {
         $ipObj = new IPAccess();
         $intIPAddress = $ipObj->__array2int($ipObj->__string2array($p_ipAddress));
         $queryStr = "SELECT DISTINCT(IdUser) FROM SubsByIP WHERE StartIP <= {$intIPAddress} " . "AND {$intIPAddress} <= (StartIP + Addresses - 1)";
         $rows = (array) $g_ado_db->GetAll($queryStr);
         if (empty($rows)) {
             $cacheService->save($cacheKey, array());
             return array();
         }
         $users = array();
         foreach ($rows as $row) {
             $users[] = $GLOBALS['controller']->getHelper('service')->getService('user')->find($row['IdUser']);
         }
         $cacheService->save($cacheKey, $users);
     }
     return $users;
 }
All Usage Examples Of IPAccess::__array2int