Validation::ip PHP Method

ip() public static method

public static ip ( $value )
    public static function ip($value)
    {
        return filter_var($value, FILTER_VALIDATE_IP) !== false;
    }

Usage Example

 /**
  * @return array or boolean false
  */
 public function findLocationByIp()
 {
     $ip = $this->findIp();
     if (empty($ip)) {
         return false;
     }
     if (Validation::ip($ip)) {
         App::import('Vendor', 'geoip', ['file' => 'geoip' . DS . 'geoip.php']);
         $gi = Net_GeoIP::getInstance(APP . 'vendors' . DS . 'geoip' . DS . 'GeoLiteCity.dat');
         $record = $gi->lookupLocation($ip);
         $gi->close();
     } else {
         $this->log('Invalid IP \'' . h($ip) . '\'', LOG_WARNING);
     }
     return !empty($record) ? $this->findLocationByCoordinates($record->latitude, $record->longitude, 1) : false;
 }
All Usage Examples Of Validation::ip