public function getMyTimezone() { //return @geoip_time_zone_by_country_and_region ( geoip_country_code_by_name('85.12.204.141')); $session = JFactory::getSession(); $cart = $session->get('cart'); $item = new stdClass(); if (isset($cart['my_timezone']) && $cart['my_timezone']) { $item->my_timezone = $cart['my_timezone']; } else { if ($_SERVER['HTTP_HOST'] == 'cloudinterpreter.tst') { $item->my_timezone = 'Europe/Moscow'; } else { $item->my_timezone = @geoip_time_zone_by_country_and_region(geoip_country_code_by_name($_SERVER['REMOTE_ADDR'])); } } if (isset($cart['my_partner_timezone']) && $cart['my_partner_timezone']) { $item->my_partner_timezone = $cart['my_partner_timezone']; } else { if ($_SERVER['HTTP_HOST'] == 'cloudinterpreter.tst') { $item->my_partner_timezone = 'Europe/Moscow'; } else { $item->my_partner_timezone = @geoip_time_zone_by_country_and_region(geoip_country_code_by_name($_SERVER['REMOTE_ADDR'])); } } if (!$item->my_timezone) { $item->my_timezone = 'Europe/Moscow'; $item->my_partner_timezone = 'Europe/Moscow'; } return $item; }
/** * {@inheritDoc} */ public function geocode($address) { if (!filter_var($address, FILTER_VALIDATE_IP)) { throw new UnsupportedOperation('The Geoip provider does not support street addresses, only IPv4 addresses.'); } // This API does not support IPv6 if (filter_var($address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { throw new UnsupportedOperation('The Geoip provider does not support IPv6 addresses, only IPv4 addresses.'); } if ('127.0.0.1' === $address) { return $this->returnResults([$this->getLocalhostDefaults()]); } $results = @geoip_record_by_name($address); if (!is_array($results)) { throw new NoResult(sprintf('Could not find "%s" IP address in database.', $address)); } if (!empty($results['region']) && !empty($results['country_code'])) { $timezone = @geoip_time_zone_by_country_and_region($results['country_code'], $results['region']) ?: null; $region = @geoip_region_name_by_code($results['country_code'], $results['region']) ?: $results['region']; } else { $timezone = null; $region = $results['region']; } return $this->returnResults([$this->fixEncoding(array_merge($this->getDefaults(), ['latitude' => $results['latitude'], 'longitude' => $results['longitude'], 'locality' => $results['city'], 'postalCode' => $results['postal_code'], 'adminLevels' => $results['region'] ? [['name' => $region, 'code' => $results['region'], 'level' => 1]] : [], 'country' => $results['country_name'], 'countryCode' => $results['country_code'], 'timezone' => $timezone]))]); }
/** * {@inheritDoc} */ public function getGeocodedData($address, $boundingBox = null) { if (!filter_var($address, FILTER_VALIDATE_IP)) { throw new UnsupportedException('The GeoipProvider does not support Street addresses.'); } // This API does not support IPv6 if (filter_var($address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { throw new UnsupportedException('The GeoipProvider does not support IPv6 addresses.'); } if ('127.0.0.1' === $address) { return $this->getLocalhostDefaults(); } $results = @geoip_record_by_name($address); if (!is_array($results)) { throw new NoResultException(sprintf('Could not find %s ip address in database.', $address)); } $timezone = @geoip_time_zone_by_country_and_region($results['country_code'], $results['region']) ?: null; $region = @geoip_region_name_by_code($results['country_code'], $results['region']) ?: $results['region']; return array_merge($this->getDefaults(), array('latitude' => $results['latitude'], 'longitude' => $results['longitude'], 'city' => $results['city'], 'zipcode' => $results['postal_code'], 'region' => $region, 'regionCode' => $results['region'], 'country' => $results['country_name'], 'countryCode' => $results['country_code'], 'timezone' => $timezone)); }
/** * {@inheritDoc} */ public function getGeocodedData($address) { if (!filter_var($address, FILTER_VALIDATE_IP)) { throw new UnsupportedException('The GeoipProvider does not support Street addresses.'); } // This API does not support IPv6 if (filter_var($address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { throw new UnsupportedException('The GeoipProvider does not support IPv6 addresses.'); } if ('127.0.0.1' === $address) { return array($this->getLocalhostDefaults()); } $results = array('country_name' => @geoip_country_name_by_name($address), 'country_code' => @geoip_country_code_by_name($address)); if ($results['country_code'] === false) { throw new NoResultException(sprintf('Could not find %s ip address in database.', $address)); } $timezone = @geoip_time_zone_by_country_and_region($results['country_code']) ?: null; $results = array_merge($this->getDefaults(), array('country' => $results['country_name'], 'countryCode' => $results['country_code'], 'timezone' => $timezone)); return array(array_map(function ($value) { return is_string($value) ? utf8_encode($value) : $value; }, $results)); }
/** * Init */ public function init() { /** * Define */ $time_zone_name = null; /* * Check user ip */ $ip = \Yii::$app->request->getUserIP(); /** * Exclude ip */ foreach ($this->changeByIp as $filter => $timezone) { if ($filter === $ip || ($pos = strpos($filter, '*')) !== false && !strncmp($ip, $filter, $pos)) { $time_zone_name = $timezone; break; } } /** * Find timezone */ if (!$time_zone_name) { try { $country = geoip_country_code_by_name($ip); $region = geoip_region_by_name($ip); $time_zone_name = geoip_time_zone_by_country_and_region($country, $region['region']); } catch (\Exception $e) { } if (!$time_zone_name) { $time_zone_name = $this->default; } } /** * Set timezone */ \Yii::$app->setTimeZone($time_zone_name); }
/** * @return string|bool */ public function getTimeZone() { $country = $this->getCountryCode(); $region = $this->getRegion(); $region = empty($region) ? null : $region; return geoip_time_zone_by_country_and_region($country, $region); }
public function processIP($ip) { $status = null; $request['ip'] = $ip; $request['type'] = self::ipVersion($ip); if ($request['type'] == 'IPv4') { $isPrivate = self::isPrivateIP($ip); if ($isPrivate) { $status = self::setStatus('IP_ADDRESS_RESERVED', null, $status); } $record = geoip_record_by_name($ip); } $countryCode = null; if ($record && is_array($record)) { try { // fetch continent by continent_code $continents = Config::inst()->get('IPInfoCache', 'Continents'); if (array_key_exists($record['continent_code'], $continents)) { $result['location']['continent_code'] = $record['continent_code']; } if (isset($record['continent_code']) && isset($continents[$record['continent_code']])) { $result['location']['continent_names']['en'] = $continents[$record['continent_code']]; } $countryCode = $record['country_code']; $result['location']['country_code'] = $countryCode; $result['location']['country_names']['en'] = $record['country_name']; $result['location']['postal_code'] = $record['postal_code']; $result['location']['city_names']['en'] = $record['city']; $result['location']['latitude'] = $record['latitude']; $result['location']['longitude'] = $record['longitude']; $result['location']['time_zone'] = geoip_time_zone_by_country_and_region($record['country_code'], $record['region']); } catch (Exception $e) { $status = self::setStatus('GEOIP_EXCEPTION', $e, $status); } } // fetch ISP details if ($request['type'] == 'IPv4') { $record = geoip_isp_by_name($ip); } if ($record) { $result['organization']['name'] = $record; $result['organization']['isp'] = $record; } if ($status) { $statusArray['code'] = self::setStatus(null, null, $status); $statusArray['message'] = self::getStatusMessage($status); // do not cache a failure $this->json = json_encode(array('request' => $request, 'status' => $statusArray, 'result' => array('maxmind-geoip-legacy' => $result))); return null; } else { // return cached success message $statusArray['code'] = self::setStatus('SUCCESS_CACHED', null, $status); $statusArray['message'] = self::getStatusMessage($status); $this->json = json_encode(array('request' => $request, 'status' => $statusArray, 'result' => array('maxmind-geoip-legacy' => $result))); } // we write a different json object with a cached status to the DB $statusArray['code'] = self::setStatus('SUCCESS', null); $statusArray['message'] = self::getStatusMessage($statusArray['code']); $dbJson = json_encode(array('request' => $request, 'status' => $statusArray, 'result' => array('maxmind-geoip-legacy' => $result))); return $dbJson; }
/** * @return string|bool */ public function getTimeZone() { try { $country = $this->getCountryCode(); $region = $this->getRegion(); $region = empty($region) ? null : $region; return geoip_time_zone_by_country_and_region($country, $region); } catch (\Exception $e) { return false; } }
<?php /* Codeine * @author bergstein@trickyplan.com * @description * @package Codeine * @version 8.x */ setFn('CountryAndRegion', function ($Call) { return geoip_time_zone_by_country_and_region($Call['Country'], $Call['Region']); });
public function getTimezone($s) { $r = $this->getRecord($s); return \geoip_time_zone_by_country_and_region($r->countryCode, $r->region); }
/** * getTimezone * * Returns the timezone for the set IP. * * @access protected * @static * @return string */ protected static function getTimezone() { return geoip_time_zone_by_country_and_region(self::getCountryCode(2), self::_getDetail('region')); }
static function getTimezone($s) { self::compat_check(); $r = self::getRecord($s); return geoip_time_zone_by_country_and_region($r['country_code'], $r['region']); }
/** * Returns the timezone for a IP (or the default on error) * * @param string $ip The IP to look up * @param string $default The default timezone to use on error * @return string The timezone (e.g. 'Europe/Dublin') */ public static function getTimezone($ip, $default) { if (!defined('GEOIP_COUNTRY_EDITION')) { return $default; } if (!geoip_db_avail(GEOIP_COUNTRY_EDITION)) { return $default; } $tz = @geoip_time_zone_by_country_and_region(@geoip_country_code_by_name($ip), @geoip_region_by_name($ip)); if ($tz === false) { $tz = @geoip_time_zone_by_country_and_region(@geoip_country_code_by_name($ip)); } if ($tz === false) { return $default; } return $tz; }