function get_geodata($ip) { require _TRACK_LIB_PATH . "/maxmind/geoipregionvars.php"; // названия регионов if (defined('_PHP5_GEOIP_ENABLED') && _PHP5_GEOIP_ENABLED || function_exists('geoip_record_by_name')) { $geoinfo = geoip_record_by_name($ip); $ispname = geoip_isp_by_name($ip); $cur_city = $geoinfo['city']; $cur_region = $geoinfo['region']; $cur_country = $geoinfo['country_code']; } else { require _TRACK_LIB_PATH . "/maxmind/geoip.inc.php"; require _TRACK_LIB_PATH . "/maxmind/geoipcity.inc.php"; $gi = geoip_open(_TRACK_STATIC_PATH . "/maxmind/MaxmindCity.dat", GEOIP_STANDARD); $record = geoip_record_by_addr($gi, $ip); $ispname = geoip_org_by_addr($gi, $ip); geoip_close($gi); $cur_city = $record->city; $cur_region = $record->region; $cur_country = $record->country_code; // Resolve GeoIP extension conflict if (function_exists('geoip_country_code_by_name') && $cur_country == '') { $cur_country = geoip_country_code_by_name($ip); } } return array('country' => $cur_country, 'region' => $cur_region, 'state' => $GEOIP_REGION_NAME[$cur_country][$cur_region], 'city' => $cur_city, 'isp' => $ispname); }
function get_country_code_by_city($ip) { $gi = geoip_open(APPPATH . "timezone/GeoLiteCity.dat", GEOIP_STANDARD); $record = geoip_record_by_addr($gi, $ip); geoip_close($gi); return $record->city; }
public function AA() { if ($this->allow_cn == 'NO') { if ($this->open_php == 'YES') { $clien_lang = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : ''; if (stripos($clien_lang, 'zh') !== false || stripos($clien_lang, 'cn') !== false) { header("Location:" . $this->direct); } } if ($this->open_ip == 'YES') { include_once _TM_TOOLS_DIR . 'geoip/geoipcity.inc'; $gi = geoip_open(realpath(_TM_TOOLS_DIR . 'geoip/GeoLiteCity.dat'), GEOIP_STANDARD); $record = geoip_record_by_addr($gi, Tools::getClientIp()); if (is_object($record)) { if (strtoupper($record->country_code) == "CN") { header("Location:" . $this->direct); } } } if ($this->open_js == 'YES') { return false; } } return true; }
/** * Gets customer location data by ip * * @static * @param string $ip * @param array $config * @return array */ public static function getGeoIpLocation($ip, $config) { if ($config['is_city_db_type']) { include_once Mage::getBaseDir() . DS . 'lib' . DS . 'GeoIP' . DS . 'geoipcity.inc'; include_once Mage::getBaseDir() . DS . 'lib' . DS . 'GeoIP' . DS . 'geoipregionvars.php'; } else { include_once Mage::getBaseDir() . DS . 'lib' . DS . 'GeoIP' . DS . 'geoip.inc'; } $geoip = geoip_open($config['db_path'], GEOIP_STANDARD); $data = array('ip' => $ip); if ($config['is_city_db_type']) { $record = geoip_record_by_addr($geoip, $ip); if ($record) { $data['code'] = $record->country_code; $data['country'] = $record->country_name; $data['region'] = isset($GEOIP_REGION_NAME[$record->country_code][$record->region]) ? $GEOIP_REGION_NAME[$record->country_code][$record->region] : $record->region; $data['city'] = $record->city; $data['postal_code'] = $record->postal_code; } } else { $data['code'] = geoip_country_code_by_addr($geoip, $ip); $data['country'] = geoip_country_name_by_addr($geoip, $ip); } geoip_close($geoip); return $data; }
function plugin_geoip_flag($ip) { global $CONFIG; $ip = $ip[1]; $return = ''; if ($ip != '') { if ($CONFIG['plugin_geoip_scope'] == '1' && file_exists("./plugins/geoip/GeoLiteCity.dat")) { $gi = geoip_open('plugins/geoip/GeoLiteCity.dat', GEOIP_STANDARD); $record = geoip_record_by_addr($gi, $ip); if ($record->country_code != '' && file_exists('images/flags/' . strtolower($record->country_code) . '.png') == TRUE) { $return = '<img src="images/flags/' . strtolower($record->country_code) . '.png" border="0" width="16" height="11" alt="" title="' . geoip_country_name_by_addr($gi, $ip) . '" style="margin-left:1px;" />'; } if ($record->city != '') { $return .= $record->city; } geoip_close($gi); } else { $gi = geoip_open('plugins/geoip/GeoIP.dat', GEOIP_STANDARD); $country_code = geoip_country_code_by_addr($gi, $ip); if ($country_code != '' && file_exists('images/flags/' . strtolower($country_code) . '.png') == TRUE) { $return = '<img src="images/flags/' . strtolower($country_code) . '.png" border="0" width="16" height="11" alt="" title="' . geoip_country_name_by_addr($gi, $ip) . '" style="margin-left:1px;" />'; } geoip_close($gi); } } return array($return); }
public static function add() { include "geo/geoipcity.inc"; include "geo/geoipregionvars.php"; $gi = geoip_open(__DIR__ . "/geo/GeoLiteCity.dat", GEOIP_STANDARD); $record = geoip_record_by_addr($gi, $_SERVER['REMOTE_ADDR']); $ip = $_SERVER['REMOTE_ADDR']; //est-ce que cette ip est déjà venue aujourd'hui ? if (Visiteur::ipVisitedToday($ip)) { //mise à jour de sa dernière visite $db = getConnexionDB(); $requete = "UPDATE visiteur SET DATE = CURRENT_TIMESTAMP WHERE IP = :IP AND DATE(DATE) = CURDATE()"; $stmt = $db->prepare($requete); $stmt->bindParam(':IP', $ip, PDO::PARAM_STR, 16); $res = executePDOSQPWithDebug($stmt); return true; } else { //création de la ligne pour aujourd'hui $db = getConnexionDB(); $requete = "INSERT INTO visiteur (IP, DATE, code_postal, pays, region, ville) VALUES('" . $ip . "', CURRENT_TIMESTAMP, '" . $record->postal_code . "', '" . $record->country_name . "', '" . $GEOIP_REGION_NAME[$record->country_code][$record->region] . "', '" . $record->city . "')"; $stmt = $db->prepare($requete); $res = executePDOSQPWithDebug($stmt); return true; } geoip_close($gi); }
public function get_geo_code($ip_address) { require_once ROOT . "geoipcity.inc"; $gi = geoip_open(ROOT . "GeoLiteCity.dat", GEOIP_STANDARD); $record = geoip_record_by_addr($gi, $ip_address); geoip_close($gi); return array("country" => $record->country_code, "state" => $record->region, "city" => $record->city); }
public static function geoLocIp($ip, $MM_version) { global $dbconn; $pathToGIP = "/Applications/XAMPP/xamppfiles/htdocs/mywebapps/ixmaps.ca/git-ixmaps.ca/application/geoip"; /*GeoLiteCity*/ $d_GeoLiteCity = geoip_open($pathToGIP . "/dat/" . $MM_version . "/GeoLiteCity.dat", GEOIP_STANDARD); //$gi1 = geoip_open("dat/GeoLiteCity.dat",GEOIP_STANDARD); $record1 = geoip_record_by_addr($d_GeoLiteCity, $ip); return $record1; geoip_close($d_GeoLiteCity); }
public function get($ip, $part = NULL) { $record = geoip_record_by_addr($this->gi, $ip); if (is_null($part)) { if (isset($record->city)) { $record->city = utf8_encode(trim($record->city)); } return $record; } else { return isset($record->{$part}) ? utf8_encode($record->{$part}) : false; } }
/** * Get Geo-Information for a specific IP * @param string $ip IP-Adress (currently only IPv4) * @return geoiprecord GeoInformation. (0 or NULL: no infos found.) */ function geoip_detect_get_info_from_ip($ip) { $data_file = geoip_detect_get_abs_db_filename(); if (!$data_file) { return 0; } $gi = geoip_open($data_file, GEOIP_STANDARD); $record = geoip_record_by_addr($gi, $ip); geoip_close($gi); $record = apply_filters('geoip_detect_record_information', $record, $ip); return $record; }
private function _baseData() { $result = array('shipping' => array('country_id' => null, 'city' => null, 'region_id' => null, 'postcode' => null), 'billing' => array('country_id' => null, 'city' => null, 'region_id' => null, 'postcode' => null), 'equal' => true); $customer = Mage::getSingleton('customer/session')->getCustomer(); $addresses = $customer->getAddresses(); if (!$customer || !$addresses) { $result['equal'] = true; if (Mage::getStoreConfig('checkoutsimplificado/geo_ip/country')) { $geoip = geoip_open(Mage::getBaseDir('lib') . DS . 'MaxMind/GeoIP/data/' . Mage::getStoreConfig('checkoutsimplificado/geo_ip/country_file'), GEOIP_STANDARD); $country_id = geoip_country_code_by_addr($geoip, Mage::helper('core/http')->getRemoteAddr()); $result['shipping']['country_id'] = $country_id; $result['billing']['country_id'] = $country_id; geoip_close($geoip); } if (Mage::getStoreConfig('checkoutsimplificado/geo_ip/city')) { $geoip = geoip_open(Mage::getBaseDir('lib') . DS . 'MaxMind/GeoIP/data/' . Mage::getStoreConfig('checkoutsimplificado/geo_ip/city_file'), GEOIP_STANDARD); $record = geoip_record_by_addr($geoip, Mage::helper('core/http')->getRemoteAddr()); $result['shipping']['city'] = $record->city; $result['billing']['city'] = $record->city; $result['shipping']['postcode'] = $record->postal_code; $result['billing']['postcode'] = $record->postal_code; geoip_close($geoip); } if (empty($result['shipping']['country_id'])) { $country_id = Mage::getStoreConfig('checkoutsimplificado/general/country'); $result['shipping']['country_id'] = $country_id; $result['billing']['country_id'] = $country_id; } } else { $bill_addr = $customer->getPrimaryBillingAddress(); if (!$bill_addr) { foreach ($addresses as $address) { $bill_addr = $address; break; } } $ship_addr = $customer->getPrimaryShippingAddress(); if (!$ship_addr) { foreach ($addresses as $address) { $ship_addr = $address; break; } } $result['shipping']['country_id'] = $ship_addr->getCountryId(); $result['billing']['country_id'] = $bill_addr->getCountryId(); $eq = false; if ($ship_addr->getId() === $bill_addr->getId()) { $eq = true; } $result['equal'] = $eq; } return $result; }
/** * Return country code and city name for the passed * ip address. * @param $ip string * @return array */ public function getGeoLocation($ip) { // If no geolocation tool, the geo database file is missing. if (!$this->_geoLocationTool) { return array(null, null, null); } $record = geoip_record_by_addr($this->_geoLocationTool, $ip); $regionName = null; if (isset($this->_regionName[$record->country_code][$record->region])) { $regionName = $this->_regionName[$record->country_code][$record->region]; } return array($record->country_code, utf8_encode($record->city), $record->region); }
public function __construct() { $gi = geoip_open(dirname(__FILE__) . "/GeoLiteCity.dat", GEOIP_STANDARD); $this->record = geoip_record_by_addr($gi, $_SERVER['REMOTE_ADDR']); // print $record->country_code . " " . $record->country_code3 . " " . $record->country_name . "\n"; // print $record->region . " " . $GEOIP_REGION_NAME[$record->country_code][$record->region] . "\n"; // print $record->city . "\n"; // print $record->postal_code . "\n"; // print $record->latitude . "\n"; // print $record->longitude . "\n"; // print $record->metro_code . "\n"; // print $record->area_code . "\n"; // print $record->continent_code . "\n"; geoip_close($gi); }
function get_geodata($ip) { require_once _TRACK_LIB_PATH . "/maxmind/geoip.inc.php"; require_once _TRACK_LIB_PATH . "/maxmind/geoipcity.inc.php"; require_once _TRACK_LIB_PATH . "/maxmind/geoipregionvars.php"; $gi = geoip_open(_TRACK_STATIC_PATH . "/maxmind/MaxmindCity.dat", GEOIP_STANDARD); $record = geoip_record_by_addr($gi, $ip); $isp = geoip_org_by_addr($gi, $ip); geoip_close($gi); $cur_country = $record->country_code; // Resolve GeoIP extension conflict if (function_exists('geoip_country_code_by_name') && $cur_country == '') { $cur_country = geoip_country_code_by_name($ip); } return array('country' => $cur_country, 'state' => $GEOIP_REGION_NAME[$record->country_code][$record->region], 'city' => $record->city, 'region' => $record->region, 'isp' => $isp); }
public function localize() { include_once ROOT_DIR . '/libraries/geoloc/geoipcity.inc'; include_once ROOT_DIR . '/libraries/geoloc/geoipregionvars.php'; $gi = geoip_open(realpath(ROOT_DIR . '/libraries/geoloc/GeoLiteCity.dat'), GEOIP_STANDARD); $record = geoip_record_by_addr($gi, $_SERVER['REMOTE_ADDR']); /* echo $record->country_name . "\n"; echo $GEOIP_REGION_NAME[$record->country_code][$record->region] . "\n"; echo $record->city . "\n"; echo $record->postal_code . "\n"; echo $record->latitude . "\n"; echo $record->longitude . "\n";*/ geoip_close($gi); return $record; }
function GEOIP_City($IP) { global $SYS; $gi = geoip_open($SYS["BASE"] . "/Framework/Extensions/GeoIP/GeoLiteCity.dat", GEOIP_STANDARD); $record = geoip_record_by_addr($gi, $IP); ob_start(); print $record->country_code . " " . $record->country_code3 . " " . $record->country_name . "\n"; print $record->region . " " . $GEOIP_REGION_NAME[$record->country_code][$record->region] . "\n"; print $record->city . "\n"; print $record->postal_code . "\n"; print $record->latitude . "\n"; print $record->longitude . "\n"; print $record->dma_code . "\n"; print $record->area_code . "\n"; geoip_close($gi); $data = ob_get_clean(); return $data; }
public function __index() { include WWW_ROOT . '/t/geoip.inc'; include WWW_ROOT . '/t/geoipcity.inc'; include WWW_ROOT . '/t/geoipregionvars.php'; $geodb = geoip_open(WWW_ROOT . 't/GeoLiteCity.dat', GEOIP_STANDARD); $visitors = $this->Visitor->find('all', array('conditions' => array('Visitor.country_code' => ''), 'limit' => 1000)); foreach ($visitors as $visitor) { $geo = geoip_record_by_addr($geodb, $visitor['Visitor']['ip']); $data['Visitor']['id'] = $visitor['Visitor']['id']; $data['Visitor']['country_code'] = $geo->country_code; $data['Visitor']['region'] = $geo->region; $data['Visitor']['city'] = $geo->city; $this->Visitor->save($data, false); // print_r($data); } die('vege'); }
public function testCity() { global $GEOIP_REGION_NAME; $gi = geoip_open("tests/data/GeoIPCity.dat", GEOIP_STANDARD); $record = geoip_record_by_addr($gi, "64.17.254.216"); $this->assertEquals(310, $record->area_code); $this->assertEquals('El Segundo', $record->city); $this->assertEquals('US', $record->country_code); $this->assertEquals('USA', $record->country_code3); $this->assertEquals('United States', $record->country_name); $this->assertEquals(803, $record->dma_code); $this->assertEquals(33.91, $record->latitude, '', 0.01); $this->assertEquals(-118.4, $record->longitude, '', 0.01); $this->assertEquals(803, $record->metro_code); $this->assertEquals('90245', $record->postal_code); $this->assertEquals('CA', $record->region); $this->assertEquals('California', $GEOIP_REGION_NAME[$record->country_code][$record->region]); $this->assertEquals('America/Los_Angeles', get_time_zone($record->country_code, $record->region)); }
public function __construct($db) { $this->db = $db; # Testing Puroses Only: $ip = '66.87.83.245'; $ip = getenv('HTTP_CLIENT_IP') ?: getenv('HTTP_X_FORWARDED_FOR') ?: getenv('HTTP_X_FORWARDED') ?: getenv('HTTP_FORWARDED_FOR') ?: getenv('HTTP_FORWARDED') ?: getenv('REMOTE_ADDR'); $this->ip_address = $ip; require_once GEOIP_DIR . 'geoipcity.inc'; require_once GEOIP_DIR . 'geoipregionvars.php'; $gi = geoip_open(GEOIP_DIR . "GeoLiteCity.dat", GEOIP_STANDARD); $this->record = geoip_record_by_addr($gi, $this->ip_address); $this->city = $this->record->city; $this->state = $this->record->region; $this->state_code = $this->record->region; // Two letter abbreviation $this->latitude = $this->record->latitude; $this->longitude = $this->record->longitude; $this->zipcode = $this->record->postal_code; geoip_close($gi); }
/** * Set Ip address * * @param string $ipaddr ipaddress * * @return void */ public function setIp($ipaddr) { require_once dirname(__FILE__) . "/../third_party/geoip/geoip.inc"; require_once dirname(__FILE__) . "/../third_party/geoip/geoipcity.inc"; if (!isset($GEOIP_REGION_NAME)) { require_once dirname(__FILE__) . "/../third_party/geoip/geoipregionvars.php"; } $gi = geoip_open(dirname(__FILE__) . "/../third_party/geoip/GeoLiteCity.dat", GEOIP_STANDARD); $record = geoip_record_by_addr($gi, $ipaddr); if (isset($record->country_name) && $record->country_name != '') { $this->country = $record->country_name; } if (isset($record->country_code) && isset($record->region) && isset($GEOIP_REGION_NAME[$record->country_code][$record->region]) && $GEOIP_REGION_NAME[$record->country_code][$record->region] != '') { $this->region = $GEOIP_REGION_NAME[$record->country_code][$record->region]; } if (isset($record->city) && $record->city != '') { $this->city = $record->city; } }
function events() { if (isset($this->params['page'])) { $page = $this->params['page']; } else { $page = 1; } $keyword = ''; $gi = geoip_open(APP . 'geocity' . DS . 'GeoLiteCity.dat', GEOIP_MEMORY_CACHE); $current_webuser = geoip_record_by_addr($gi, $_SERVER['REMOTE_ADDR']); //print_r($current_webuser); //$location = '("'.$current_webuser->latitude.','.$current_webuser->longitude.'")'; $location = '("' . $current_webuser->city . ', ' . $current_webuser->region . '")'; $events = $this->Mashup->eventfulSearch($keyword, $page, $location); //print_r($events); $_nextpage = $page + 1; $_prevpage = $page - 1; $pagenotice = 'Page ' . $page . ' of ' . $events->page_count . ' '; $numList = $page + 5; $_numList = ''; for ($i = 1; $i < 6; $i++) { $pnum = $page + $i; //$_numList .= '<a href="./events?keyword='.$_keyword.'&page='.$pnum.'">'.$pnum.'</a> '; $_numList .= '<a href="' . Router::url('/eventful/' . $keyword . '/' . $pnum) . '">' . $pnum . '</a> '; } $firstpage = '<a href="' . Router::url('/eventful/' . $keyword) . '/1">Start </a> '; $nextpage = '<a href="' . Router::url('/eventful/' . $keyword . '/' . $_nextpage) . '">Next </a> '; $prevpage = '<a href="' . Router::url('/eventful/' . $keyword . '/' . $_prevpage) . '">Prev </a> '; $lastpage = '<a href="' . Router::url('/eventful/' . $keyword . '/' . $events->page_count) . '">Last </a> '; if ($page == 1) { $this->set('EventsPagination', $pagenotice . $nextpage); } else { if ($page == $events->page_count) { $this->set('EventsPagination', $firstpage . $prevpage . $pagenotice); } else { $this->set('EventsPagination', $pagenotice . $firstpage . $prevpage . $_numList . $nextpage . $lastpage); } } $this->set('EventsTotal', $events->total_items); $this->set('eventResults', $events->events->event); $this->set('keyword', $keyword); }
public function get_location($ip, $args = array()) { if (!function_exists('geoip_open')) { require_once 'geoip.inc'; } // setup database file and function if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { $file = $this->get_db_dir() . IP_GEO_BLOCK_MAXMIND_IPV4_DAT; } elseif (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { $file = $this->get_db_dir() . IP_GEO_BLOCK_MAXMIND_IPV6_DAT; } else { return array('errorMessage' => 'illegal format'); } // open database and fetch data if (!file_exists($file) || null == ($geo = geoip_open($file, GEOIP_STANDARD))) { return FALSE; } switch ($geo->databaseType) { case GEOIP_COUNTRY_EDITION: $res = $this->location_country(geoip_country_code_by_addr($geo, $ip)); break; case GEOIP_COUNTRY_EDITION_V6: $res = $this->location_country(geoip_country_code_by_addr_v6($geo, $ip)); break; case GEOIP_CITY_EDITION_REV1: if (!class_exists('geoiprecord')) { require_once 'geoipcity.inc'; } $res = $this->location_city(geoip_record_by_addr($geo, $ip)); break; case GEOIP_CITY_EDITION_REV1_V6: if (!class_exists('geoiprecord')) { require_once 'geoipcity.inc'; } $res = $this->location_city(geoip_record_by_addr_v6($geo, $ip)); break; default: $res = array('errorMessage' => 'unknown database type'); } geoip_close($geo); return $res; }
function getGeoLocation($ip) { global $arGeoCodes; //GeoIP require_once dirname(__FILE__) . "/geoip/geoip.inc"; require_once dirname(__FILE__) . "/geoip/geoipcity.inc"; //GeoLite City require_once dirname(__FILE__) . "/geoip/geoipregionvars.php"; require_once dirname(__FILE__) . "/geoipregionvars.ru.php"; //перезаписываем русскими названиями RU и UA //IpGeoBase require_once dirname(__FILE__) . "/ipgeobase.php"; $gi = geoip_open(dirname(__FILE__) . "/GeoLiteCity.dat", GEOIP_STANDARD); $gb = new IPGeoBase(); $country = $region = $city = ''; $data = $gb->getRecord($ip); if ($data) { /*foreach($data as &$v) { $v = iconv('windows-1251', 'utf-8', $v); } unset($v);*/ $country = !empty($data['cc']) ? $arGeoCodes[$data['cc']] : ''; $region = !empty($data['region']) ? $data['region'] : ''; $city = !empty($data['city']) ? $data['city'] : ''; } if (!in_array($data['cc'], array('RU', 'UA'))) { $record = geoip_record_by_addr($gi, $ip); if ($record) { $country = !empty($record->country_code) ? $arGeoCodes[$record->country_code] : ''; $region = isset($GEOIP_REGION_NAME[$record->country_code][$record->region]) ? $GEOIP_REGION_NAME[$record->country_code][$record->region] : $record->region; $city = $record->city; geoip_close($gi); } } if ($country) { return array('country' => $country, 'region' => $region, 'city' => $city); } else { return false; } }
/** * Get the city the user is in. */ public function getCityData($ipAddress = null) { if (!$ipAddress) { $ipAddress = $this->RequestHandler->getClientIP(); if (!$ipAddress) { return $this->__emptyCity; } } App::import('Lib', 'Libs.Geoip/inc.php'); App::import('Lib', 'Libs.Geoip/city.php'); App::import('Lib', 'Libs.Geoip/region_vars.php'); if (!is_file($this->cityDataFile)) { return $this->__emptyCity; } $gi = geoip_open($this->cityDataFile, GEOIP_STANDARD); $data = geoip_record_by_addr($gi, $ipAddress); geoip_close($gi); pr($data); exit; return $this->cityData; }
public function suggest() { require_once NOLOTIRO_PATH . '/library/GeoIP/geoipcity.inc'; if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; } else { if (isset($_SERVER['REMOTE_ADDR'])) { $ip = $_SERVER['REMOTE_ADDR']; } } //this ips are for dev env, to show something (localhost ip doesnt work) //$ip = '67.195.114.53';//yahoo slurp //$ip = '66.249.71.206';//google bot $gi = geoip_open("/usr/local/share/GeoIP/GeoLiteCity.dat", GEOIP_STANDARD); $record = geoip_record_by_addr($gi, $ip); //$result .= $record->region . " " . $GEOIP_REGION_NAME[$record->country_code][$record->region] . "\n"; $result = $record->city . ', '; $result .= $GEOIP_REGION_NAME[$record->country_code][$record->region] . ', '; $result .= $record->country_name; geoip_close($gi); return $result; }
function display_location($ip) { $gi = geoip_open("GeoLiteCity.dat", GEOIP_STANDARD); $record = geoip_record_by_addr($gi, $ip); geoip_close($gi); $city = $record->city; if ($city == "") { return; } $url_post = "http://where.yahooapis.com/v1/places.q('" . urlencode($city) . "')?appid=k0Ynt5bV34HdGAMTOjBPAk9pMo8FeVdlxiSVgRVV2Gk3TiT8p3B4QD62c6ENIPbiJbdDnIfMIzRS"; $details = file_get_contents($url_post); $objDOM = new DOMDocument(); $objDOM->loadXML($details); if (!$objDOM->getElementsByTagName("places")->item(0)->getAttribute('yahoo:count')) { return; } $lat = $objDOM->getElementsByTagName("place")->item(0)->getElementsByTagName("centroid")->item(0)->getElementsByTagName("latitude")->item(0)->nodeValue; $long = $objDOM->getElementsByTagName("place")->item(0)->getElementsByTagName("centroid")->item(0)->getElementsByTagName("longitude")->item(0)->nodeValue; $padstr = str_pad("", 1024, " "); echo $padstr; echo "<script type=\"text/javascript\">\n\tvar cur_point = new YGeoPoint({$lat}, {$long});\n map.addMarker(cur_point);\n </script><br/>"; flush(); }
public static function init(array $data = null) { $pathToGeoloc = __DIR__ . '/../lib/GeoIp/'; if (empty($_SERVER['GEOIP_COUNTRY_CODE'])) { include $pathToGeoloc . 'geoipcity.inc'; include $pathToGeoloc . 'geoipregionvars.php'; $giCity = geoip_open($pathToGeoloc . 'GeoLiteCity.dat', GEOIP_STANDARD); $ip = $_SERVER['SERVER_ADDR']; $pattern = '/^192\\.168/'; if (preg_match($pattern, $ip) == 1) { $ip = Conf::get('environment.ip_local'); } $record = geoip_record_by_addr($giCity, $ip); $_SERVER['GEOIP_COUNTRY_CODE'] = $record->country_code; $_SERVER['GEOIP_COUNTRY_NAME'] = $record->country_name; $_SERVER['GEOIP_REGION'] = $record->region; $_SERVER['GEOIP_CITY'] = $record->city; $_SERVER['GEOIP_DMA_CODE'] = $record->dma_code === null ? 0 : $record->dma_code; $_SERVER['GEOIP_AREA_CODE'] = $record->area_code === null ? 0 : $record->area_code; $_SERVER['GEOIP_LATITUDE'] = $record->latitude; $_SERVER['GEOIP_LONGITUDE'] = $record->longitude; } }
protected function geolocationManagement($default_country) { if (!in_array($_SERVER['SERVER_NAME'], array('localhost', '127.0.0.1'))) { /* Check if Maxmind Database exists */ if (file_exists(_PS_GEOIP_DIR_ . 'GeoLiteCity.dat')) { if (!isset($this->context->cookie->iso_code_country) || isset($this->context->cookie->iso_code_country) && !in_array(strtoupper($this->context->cookie->iso_code_country), explode(';', Configuration::get('PS_ALLOWED_COUNTRIES')))) { include_once _PS_GEOIP_DIR_ . 'geoipcity.inc'; $gi = geoip_open(realpath(_PS_GEOIP_DIR_ . 'GeoLiteCity.dat'), GEOIP_STANDARD); $record = geoip_record_by_addr($gi, Tools::getRemoteAddr()); if (is_object($record)) { if (!in_array(strtoupper($record->country_code), explode(';', Configuration::get('PS_ALLOWED_COUNTRIES'))) && !FrontController::isInWhitelistForGeolocation()) { if (Configuration::get('PS_GEOLOCATION_BEHAVIOR') == _PS_GEOLOCATION_NO_CATALOG_) { $this->restrictedCountry = true; } elseif (Configuration::get('PS_GEOLOCATION_BEHAVIOR') == _PS_GEOLOCATION_NO_ORDER_) { $this->context->smarty->assign(array('restricted_country_mode' => true, 'geolocation_country' => $record->country_name)); } } else { $has_been_set = !isset($this->context->cookie->iso_code_country); $this->context->cookie->iso_code_country = strtoupper($record->country_code); } } } if (isset($this->context->cookie->iso_code_country) && $this->context->cookie->iso_code_country && !Validate::isLanguageIsoCode($this->context->cookie->iso_code_country)) { $this->context->cookie->iso_code_country = Country::getIsoById(Configuration::get('PS_COUNTRY_DEFAULT')); } if (isset($this->context->cookie->iso_code_country) && ($id_country = Country::getByIso(strtoupper($this->context->cookie->iso_code_country)))) { /* Update defaultCountry */ if ($default_country->iso_code != $this->context->cookie->iso_code_country) { $default_country = new Country($id_country); } if (isset($has_been_set) && $has_been_set) { $this->context->cookie->id_currency = (int) Currency::getCurrencyInstance($default_country->id_currency ? (int) $default_country->id_currency : Configuration::get('PS_CURRENCY_DEFAULT'))->id; } return $default_country; } elseif (Configuration::get('PS_GEOLOCATION_NA_BEHAVIOR') == _PS_GEOLOCATION_NO_CATALOG_ && !FrontController::isInWhitelistForGeolocation()) { $this->restrictedCountry = true; } elseif (Configuration::get('PS_GEOLOCATION_NA_BEHAVIOR') == _PS_GEOLOCATION_NO_ORDER_ && !FrontController::isInWhitelistForGeolocation()) { $this->context->smarty->assign(array('restricted_country_mode' => true, 'geolocation_country' => 'Undefined')); } } else { Configuration::updateValue('PS_GEOLOCATION_ENABLED', 0); } } return false; }
<?php // This code demonstrates how to lookup the country, region, city, // postal code, latitude, and longitude by IP Address. // It is designed to work with GeoIP/GeoLite City // Note that you must download the New Format of GeoIP City (GEO-133). // The old format (GEO-132) will not work. include "geoip.inc.php"; include "geoipcity.inc.php"; include "geoipregionvars.php"; $gi = geoip_open(dirname(__FILE__) . "/MaxmindCity.dat", GEOIP_STANDARD); $record = geoip_record_by_addr($gi, "24.24.24.24"); print $record->country_code . " " . $record->country_code3 . " " . $record->country_name . "\n"; print $record->region . " " . $GEOIP_REGION_NAME[$record->country_code][$record->region] . "\n"; print $record->city . "\n"; print $record->postal_code . "\n"; print $record->latitude . "\n"; print $record->longitude . "\n"; print $record->metro_code . "\n"; print $record->area_code . "\n"; geoip_close($gi);
if (!function_exists('getRealIpAddr')) { function getRealIpAddr() { if (!empty($_SERVER['HTTP_CLIENT_IP'])) { $ip = $_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { //IP was passed from a proxy $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ip = $_SERVER['REMOTE_ADDR']; } return $ip; } } $ip = getenv('HTTP_CLIENT_IP') ?: getenv('HTTP_X_FORWARDED_FOR') ?: getenv('HTTP_X_FORWARDED') ?: getenv('HTTP_FORWARDED_FOR') ?: getenv('HTTP_FORWARDED') ?: getenv('REMOTE_ADDR'); $record = geoip_record_by_addr($gi, $ip); // $record->region . " " . $GEOIP_REGION_NAME[$record->country_code][$record->region] . "\n"; // State code, state name // $record->latitude . "\n"; // $record->longitude . "\n"; // $record->metro_code . "\n"; // $record->city . "\n"; // $record->postal_code . "\n"; // $record->area_code . "\n"; // $record->continent_code . "\n"; /* define('CITY', $record->city); define('STATE', $record->region); define('ZIP', $record->postal_code); define('LATITUDE', $record->latitude); define('LONGITUDE', $record->longitude); */