本文整理汇总了PHP中geoip_record_by_name函数的典型用法代码示例。如果您正苦于以下问题:PHP geoip_record_by_name函数的具体用法?PHP geoip_record_by_name怎么用?PHP geoip_record_by_name使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了geoip_record_by_name函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: get_geodata
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);
}
开发者ID:conversionstudio,项目名称:cpatracker,代码行数:27,代码来源:functions.php
示例2: geocode
/**
* {@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]))]);
}
开发者ID:TomLous,项目名称:Geocoder,代码行数:28,代码来源:Geoip.php
示例3: getGeoIpByMaxMind
private function getGeoIpByMaxMind()
{
$ip = isset($this->request->server['HTTP_X_FORWARDED_FOR']) && $this->request->server['HTTP_X_FORWARDED_FOR'] ? $this->request->server['HTTP_X_FORWARDED_FOR'] : 0;
$ip = $ip ? $ip : $this->request->server['REMOTE_ADDR'];
$part = explode(".", $ip);
$ip_int = 0;
if (count($part) == 4) {
$ip_int = $part[3] + 256 * ($part[2] + 256 * ($part[1] + 256 * $part[0]));
}
$geo = $this->cache->get('maxmind.' . $ip_int);
if (!isset($geo)) {
if (function_exists('apache_note') && ($code = apache_note('GEOIP_COUNTRY_CODE'))) {
if ($country_id = $this->getCountryIdbyISO($code)) {
$geo = array('country_id' => $country_id, 'zone_id' => '', 'city' => '', 'postcode' => '');
}
} else {
if (function_exists('geoip_record_by_name') && ($code = geoip_record_by_name($ip))) {
if ($country_id = $this->getCountryIdbyISO($code['country_code'])) {
$geo = array('country_id' => $country_id, 'zone_id' => '', 'city' => '', 'postcode' => '');
}
}
}
}
$this->cache->set('maxmind.' . $ip_int, isset($geo) ? $geo : false);
return $geo;
}
开发者ID:ralfeus,项目名称:moomi-daeri.com,代码行数:26,代码来源:simplegeo.php
示例4: location
/**
* Return geolocation data based on specified/auto-detected IP address
* @return array|FALSE
* @param $ip string
**/
function location($ip = NULL)
{
$fw = \Base::instance();
$web = \Web::instance();
if (!$ip) {
$ip = $fw->get('IP');
}
$public = filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6 | FILTER_FLAG_NO_RES_RANGE | FILTER_FLAG_NO_PRIV_RANGE);
if (function_exists('geoip_db_avail') && geoip_db_avail(GEOIP_CITY_EDITION_REV1) && ($out = @geoip_record_by_name($ip))) {
$out['request'] = $ip;
$out['region_code'] = $out['region'];
$out['region_name'] = geoip_region_name_by_code($out['country_code'], $out['region']);
unset($out['country_code3'], $out['region'], $out['postal_code']);
return $out;
}
if (($req = $web->request('http://www.geoplugin.net/json.gp' . ($public ? '?ip=' . $ip : ''))) && ($data = json_decode($req['body'], TRUE))) {
$out = array();
foreach ($data as $key => $val) {
if (!strpos($key, 'currency') && $key !== 'geoplugin_status' && $key !== 'geoplugin_region') {
$out[$fw->snakecase(substr($key, 10))] = $val;
}
}
return $out;
}
return FALSE;
}
开发者ID:mm999,项目名称:selfoss,代码行数:31,代码来源:geo.php
示例5: geoip_record
public function geoip_record($ip)
{
if (!extension_loaded('geoip')) {
return array();
}
return @geoip_record_by_name($ip);
}
开发者ID:openbuildings,项目名称:site-versions,代码行数:7,代码来源:Defaults.php
示例6: __construct
/**
*
* @param string $ip user ip address
* @param string $userAgentStr user agent string
*/
public function __construct($ip = null, $userAgentStr = null)
{
$this->ip = $ip ? $ip : $this->getIp();
if ($userAgentStr) {
$this->userAgent = $userAgentStr;
} elseif (isset($_SERVER['HTTP_USER_AGENT'])) {
$this->userAgent = $_SERVER['HTTP_USER_AGENT'];
}
$this->host = $this->getHostname();
if (isset($_SERVER['HTTP_REFERER'])) {
$this->referer = $_SERVER['HTTP_REFERER'];
}
// get extended informations
if (extension_loaded('geoip')) {
$this->geoipSupports = true;
}
if ($this->ip && $this->geoipSupports) {
if ($record = @geoip_record_by_name($this->ip)) {
$this->continent = @$record['continent_code'];
$this->countryCode = @$record['country_code'];
$this->country = @$record['country_name'];
$this->city = @$record['city'];
$this->latitude = @$record['latitude'];
$this->longitude = @$record['longitude'];
}
}
// if browscap string is set in php.ini, we can use get_browser function
if ($browscapStr = ini_get('browscap')) {
$this->browser = (object) get_browser($userAgentStr, true);
} else {
// $browscap = new Browscap( kernel()->cacheDir );
// $this->browser = (object) $browscap->getBrowser( $userAgentStr , true);
}
}
开发者ID:corneltek,项目名称:phifty,代码行数:39,代码来源:BrowserClient.php
示例7: initController
public static function initController()
{
$id = Request::get('Currency', null, 'COOKIE');
$Current = new Currency();
$Default = Currency::findDefault();
$code = null;
if (function_exists('geoip_record_by_name')) {
$arr = @geoip_record_by_name(Request::get('REMOTE_ADDR', '', 'SERVER'));
$code = isset($arr['country_code']) ? $arr['country_code'] : null;
}
$arr = Currency::findCurrencies(true);
foreach ($arr as $i => $Currency) {
if ($Currency->Id == $id) {
$Current = $Currency;
break;
}
}
if (!$Current->Id && $code) {
foreach ($arr as $Currency) {
if ($Currency->hasCountry($code)) {
$Current = $Currency;
break;
}
}
}
if (!$Current->Id) {
foreach ($arr as $Currency) {
$Current = $Currency;
break;
}
}
Runtime::set('CURRENCY_DEFAULT', $Default);
Runtime::set('CURRENCY_CURRENT', $Current);
return false;
}
开发者ID:vosaan,项目名称:ankor.local,代码行数:35,代码来源:application.php
示例8: query
function query($args, $document)
{
$this->validate($args);
$xml = new xml();
switch ($this->method) {
case 'record':
isset($args['host']) or runtime_error('GeoIP host parameter not found');
$root = $xml->element($this->root[0]);
$xml->append($root);
if ($record = geoip_record_by_name($args['host'])) {
$country = $xml->element('country');
$root->append($country);
$country->append($xml->element('alpha2', $record['country_code']));
$country->append($xml->element('alpha3', $record['country_code3']));
$country->append($xml->element('name', $record['country_name']));
$root->append($xml->element('region', $record['region']));
$root->append($xml->element('city', $record['city']));
$root->append($xml->element('latitude', $record['latitude']));
$root->append($xml->element('longitude', $record['longitude']));
}
break;
default:
runtime_error('Unknown GeoIP method: ' . $this->method);
}
return $xml;
}
开发者ID:nyan-cat,项目名称:easyweb,代码行数:26,代码来源:geoip_procedure.php
示例9: mirror_closest
function mirror_closest()
{
global $_SERVER, $MIRRORS;
// Get the current longitude for the client...
if (!extension_loaded("geoip.so") || $_SERVER["REMOTE_ADDR"] == "::1" || $_SERVER["REMOTE_ADDR"] == "127.0.0.1") {
$lon = -120;
} else {
$current = geoip_record_by_name($_SERVER["REMOTE_ADDR"]);
$lon = $current["longitude"];
}
// Loop through the mirrors to find the closest one, currently just using
// the longitude...
$closest_mirror = "";
$closest_distance = 999;
reset($MIRRORS);
foreach ($MIRRORS as $mirror => $data) {
$distance = abs($lon - $data[2]);
if ($distance > 180) {
$distance = 360 - $distance;
}
if ($distance < $closest_distance) {
$closest_mirror = $mirror;
$closest_distance = $distance;
}
}
return $closest_mirror;
}
开发者ID:jokepinocchio,项目名称:MiniXML,代码行数:27,代码来源:mirrors.php
示例10: getLocationFromIp
public static function getLocationFromIp($ipAddress = false)
{
if (!$ipAddress) {
$ipAddress = self::getRealIp();
}
$city = null;
$country = null;
$location = false;
if (function_exists('geoip_record_by_name')) {
$oe = set_error_handler('process_error_backtrace_null');
$location = @geoip_record_by_name($ipAddress);
set_error_handler($oe);
}
if ($location && !empty($location['city'])) {
$city = $location['city'];
}
if ($location && !empty($location['country_name'])) {
$country = $location['country_name'];
}
if ($city == '0') {
$city = null;
}
if ($country == '0') {
$country = null;
}
return ['country' => utf8_encode($country), 'city' => utf8_encode($city)];
}
开发者ID:dylnio,项目名称:packages-util,代码行数:27,代码来源:IpUtil.php
示例11: getPosition
/**
* @return bool|GeoIPPosition
*/
public function getPosition()
{
$data = @geoip_record_by_name($this->_ip);
if (!$data || !is_array($data) || !array_key_exists('latitude', $data) || !array_key_exists('longitude', $data)) {
return false;
}
return new GeoIPPosition($data['latitude'], $data['longitude']);
}
开发者ID:marsianin,项目名称:yii2-geoip,代码行数:11,代码来源:GeoIPWrapper.php
示例12: setHost
function setHost($host)
{
$this->host = $host;
try {
$this->data = geoip_record_by_name($this->host);
} catch (\yii\base\ErrorException $E) {
\Yii::error($E->getMessage(), __METHOD__);
}
}
开发者ID:hysdop,项目名称:YobaCMS,代码行数:9,代码来源:GeoIP.php
示例13: getLocationRecord
public static function getLocationRecord($ip)
{
$region = geoip_record_by_name($ip);
if (false !== $region) {
return !empty($region['city']) ? sprintf(self::$locationFmt, utf8_encode($region['city']), $region['region'], $region['country_name'], $region['country_code']) : sprintf(self::$locationFmtSimple, $region['country_name'], $region['country_code']);
} else {
return 'GeoIP error: unable to determine location';
}
}
开发者ID:norv,项目名称:EosAlpha,代码行数:9,代码来源:main.php
示例14: init
/**
* @inheritdoc
*/
public function init()
{
parent::init();
if (!geoip_db_avail(GEOIP_COUNTRY_EDITION)) {
throw new Exception('GeoIP country database not available.');
}
if (empty($this->host)) {
$this->host = \Yii::$app->request->userIP;
}
$this->data = geoip_record_by_name($this->host);
}
开发者ID:rmrevin,项目名称:yii2-geoip,代码行数:14,代码来源:HostInfo.php
示例15: details
public static function details($_model = null)
{
$module = static::$module;
$modeler = $module::model()->modeler;
$_model = $_model == null ? forward_static_call_array(array($modeler, 'model'), array()) : forward_static_call_array(array($modeler, 'model'), array($_model));
$_o = (object) null;
$_o->size = 'large';
$_o->icon_type = 'menu-icon';
$_o->icon_background = 'session-icon-background';
$_o->menu = (object) null;
$_o->menu->items = array();
$items[] = CardKit::onTapEventsXHRCallMenuItem('Delete Session', 'cards/session/delete', array($_model->id));
$_o->body[] = CardKit::nextInCollection((object) array('model_id' => $_model->id, 'details_route' => 'cards/session/details'));
$_o->body = array();
$dom_id = FormInputComponent::uniqueHash('', '');
$html = $js = array();
$js[] = DOMElementKitJS::documentEventOff('keydown');
$js[] = '$(document).on(\'keydown\',(function(e){';
$js[] = 'if (e.keyCode == 66){';
$js[] = 'new XHRCall({route:"operations/session/blockIP",inputs:[' . $_model->id . ']});';
$js[] = '}';
$js[] = 'if(next_id != \'' . $_model->id . '\'){';
$js[] = 'if (e.keyCode == 39){';
$js[] = 'new XHRCall({route:"cards/session/details",inputs:[next_id]});';
$js[] = '}';
$js[] = 'if (e.keyCode == 46){';
$js[] = 'new XHRCall({route:\'operations/session/delete\',inputs: [' . $_model->id . '],done_callback:function(){ new XHRCall({route:\'cards/session/details\',inputs:[next_id]});} });';
$js[] = '}';
$js[] = '}else{';
$js[] = 'if (e.keyCode == 46){';
$js[] = 'new XHRCall({route:\'operations/session/delete\',inputs: [' . $_model->id . ']});';
$js[] = '}';
$js[] = '}';
$js[] = '}));';
$_o->body[] = CardKitHTML::sublineBlock('Name');
$_o->body[] = $_model->name;
$_o->body[] = CardKitHTML::sublineBlock('Ip Address');
$_o->body[] = $_model->ip_address;
$_o->body[] = CardKitHTML::sublineBlock('Data');
$_o->body[] = '<textarea style="width:20em; height:10em;">' . $_model->session_data . '</textarea>';
$location = geoip_record_by_name($_model->ip_address);
if ($location) {
$_o->body[] = CardKitHTML::sublineBlock('Geo Location');
$_o->body[] = $location['city'] . (!empty($location['region']) ? ' ' . $location['region'] : '') . ', ' . $location['country_name'] . (!empty($location['postal_code']) ? ', ' . $location['postal_code'] : '');
}
$_o->body[] = CardKitHTML::sublineBlock('Session Started');
$_o->body[] = date('g:ia \\o\\n l jS F Y', $_model->session_start);
$_o->body[] = CardKitHTML::sublineBlock('Last Sign In');
$_o->body[] = CardKit::deleteInCollection((object) array('route' => 'operations/session/delete', 'model_id' => $_model->id));
$_o->body[] = CardKitHTML::modelId($_model);
return $_o;
}
开发者ID:shawnlawyer,项目名称:framework,代码行数:52,代码来源:Cards.class.php
示例16: run
public function run()
{
parent::run();
if (function_exists('geoip_record_by_name')) {
if ($this->iprecord = @geoip_record_by_name($this->ip)) {
$this->renderHeader();
if ($this->map) {
$this->renderMap();
}
$this->renderInfo();
}
}
}
开发者ID:hiqdev,项目名称:hipanel-module-domain,代码行数:13,代码来源:GeoIP.php
示例17: getLocation
/**
* Uses the GeoIP PECL module to get a visitor's location based on their IP address.
*
* This function will return different results based on the data available. If a city
* database can be detected by the PECL module, it may return the country code,
* region code, city name, area code, latitude, longitude and postal code of the visitor.
*
* Alternatively, if only the country database can be detected, only the country code
* will be returned.
*
* The GeoIP PECL module will detect the following filenames:
* - GeoIP.dat
* - GeoIPCity.dat
* - GeoIPISP.dat
* - GeoIPOrg.dat
*
* Note how GeoLiteCity.dat, the name for the GeoLite city database, is not detected
* by the PECL module.
*
* @param array $info Must have an 'ip' field.
* @return array
*/
public function getLocation($info)
{
$ip = $this->getIpFromInfo($info);
$result = array();
// get location data
if (self::isCityDatabaseAvailable()) {
// Must hide errors because missing IPV6:
$location = @geoip_record_by_name($ip);
if (!empty($location)) {
$result[self::COUNTRY_CODE_KEY] = $location['country_code'];
$result[self::REGION_CODE_KEY] = $location['region'];
if ($location['region'] == "18" && $location['city'] == "Milan") {
$result[self::REGION_CODE_KEY] = "09";
}
$result[self::CITY_NAME_KEY] = utf8_encode($location['city']);
$result[self::AREA_CODE_KEY] = $location['area_code'];
$result[self::LATITUDE_KEY] = $location['latitude'];
$result[self::LONGITUDE_KEY] = $location['longitude'];
$result[self::POSTAL_CODE_KEY] = $location['postal_code'];
}
} else {
if (self::isRegionDatabaseAvailable()) {
$location = @geoip_region_by_name($ip);
if (!empty($location)) {
$result[self::REGION_CODE_KEY] = $location['region'];
$result[self::COUNTRY_CODE_KEY] = $location['country_code'];
}
} else {
$result[self::COUNTRY_CODE_KEY] = @geoip_country_code_by_name($ip);
}
}
// get organization data if the org database is available
if (self::isOrgDatabaseAvailable()) {
$org = @geoip_org_by_name($ip);
if ($org !== false) {
$result[self::ORG_KEY] = utf8_encode($org);
}
}
// get isp data if the isp database is available
if (self::isISPDatabaseAvailable()) {
$isp = @geoip_isp_by_name($ip);
if ($isp !== false) {
$result[self::ISP_KEY] = utf8_encode($isp);
}
}
if (empty($result)) {
return false;
}
$this->completeLocationResult($result);
return $result;
}
开发者ID:parruc,项目名称:piwik,代码行数:73,代码来源:Pecl.php
示例18: query_direct
function query_direct($args)
{
switch ($this->method) {
case 'record':
isset($args['_host']) or backend_error('bad_query', 'GeoIP _host argument missing');
if ($record = geoip_record_by_name($args['_host'])) {
return (object) ['country' => ['alpha2' => $record['country_code'], 'alpha3' => $record['country_code3'], 'name' => $record['country_name']], 'region' => $record['region'], 'city' => $record['city'], 'latitude' => $record['latitude'], 'longitude' => $record['longitude']];
} else {
!$this->required or backend_error('bad_input', 'Empty response from GeoIP procedure');
}
break;
}
return null;
}
开发者ID:nyan-cat,项目名称:easyweb,代码行数:14,代码来源:geoip_procedure.php
示例19: Lookup
public function Lookup()
{
if ($this->city_avail) {
$ar = geoip_record_by_name($_SERVER['REMOTE_ADDR']);
$this->country_code = $ar["country_code"];
$this->country_short_name = $ar["country_code3"];
$this->country_full_name = $ar["country_name"];
$this->region_name = $ar["region"];
$this->city_name = $ar["city"];
//Extended info
$this->postal_code = $ar["postal_code"];
$this->latitude = $ar["latitude"];
$this->longitude = $ar["longitude"];
} elseif ($this->country_avail) {
$this->country_code = geoip_country_code_by_name($_SERVER['REMOTE_ADDR']);
}
}
开发者ID:rasuldev,项目名称:torino,代码行数:17,代码来源:geoip_extension.php
示例20: getRecord
public function getRecord($s)
{
$arr = \geoip_record_by_name($s);
$res = new GeoIpRecord();
$res->continentCode = $arr['continent_code'];
$res->countryCode = $arr['country_code'];
$res->countryCode3 = $arr['country_code3'];
$res->countryName = $arr['country_name'];
$res->region = $arr['region'];
$res->city = $arr['city'];
$res->postalCode = $arr['postal_code'];
$res->latitude = $arr['latitude'];
$res->longitude = $arr['longitude'];
$res->dmaCode = $arr['dma_code'];
$res->areaCode = $arr['area_code'];
return $res;
}
开发者ID:martinlindhe,项目名称:core3,代码行数:17,代码来源:GeoIp.php
注:本文中的geoip_record_by_name函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论