当前位置: 首页>>代码示例>>PHP>>正文


PHP geoip_db_avail函数代码示例

本文整理汇总了PHP中geoip_db_avail函数的典型用法代码示例。如果您正苦于以下问题:PHP geoip_db_avail函数的具体用法?PHP geoip_db_avail怎么用?PHP geoip_db_avail使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了geoip_db_avail函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getCountryByIp

 /**
  * Get the country by IP
  * Return an array with : short name, like 'us', long name, like 'United States and response like 'OK' or <error_message> '
  * @access public
  * @param string $ip
  * @return array
  */
 public function getCountryByIp($ip)
 {
     $country = array(0 => 'unknown', 1 => 'NA', 'response' => 'OK');
     if (Dot_Kernel::validIp($ip) != "public") {
         return $country;
     }
     if (extension_loaded('geoip') == false) {
         // GeoIp extension is not active
         $api = new Dot_Geoip_Country();
         $geoipPath = $this->config->resources->geoip->path;
         if (file_exists($geoipPath)) {
             $country = $api->getCountryByAddr($geoipPath, $ip);
         } else {
             $country['response'] = 'Warning: ' . $this->option->warningMessage->modGeoIp;
         }
     }
     if (function_exists('geoip_db_avail') && geoip_db_avail(GEOIP_COUNTRY_EDITION) && 'unknown' == $country[0]) {
         //if GeoIP.dat file exists
         $countryCode = geoip_country_code_by_name($ip);
         $countryName = geoip_country_name_by_name($ip);
         $country[0] = $countryCode != false ? $countryCode : 'unknown';
         $country[1] = $countryName != false ? $countryName : 'NA';
     }
     if ('unknown' == $country[0]) {
         // GeoIp extension is active, but .dat files are missing
         $api = new Dot_Geoip_Country();
         $geoipPath = $this->config->resources->geoip->path;
         if (file_exists($geoipPath)) {
             $country = $api->getCountryByAddr($geoipPath, $ip);
         } else {
             $country['response'] = 'Warning: ' . $this->option->warningMessage->modGeoIp;
         }
     }
     return $country;
 }
开发者ID:sandeepdwarkapuria,项目名称:dotkernel,代码行数:42,代码来源:Geoip.php

示例2: 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

示例3: getIPCountry

 static function getIPCountry($ip)
 {
     if (function_exists('geoip_db_avail') && geoip_db_avail(GEOIP_COUNTRY_EDITION)) {
         try {
             try {
                 return geoip_country_code_by_name($ip);
             } catch (Exception $e) {
             }
         } catch (ErrorException $e) {
         }
     }
     try {
         $country = json_decode(file_get_contents('https://freegeoip.net/json/' . $ip));
         if (isset($country) && isset($country->country_code) && $country->country_code != '') {
             return $country->country_code;
         }
     } catch (Exception $e) {
     }
     try {
         $country = json_decode(file_get_contents('http://ip-api.com/json/' . $ip));
         if (isset($country) && isset($country->countryCode) && $country->countryCode != '') {
             return $country->countryCode;
         }
     } catch (Exception $e) {
     }
     try {
         $country = trim(file_get_contents("http://api.hostip.info/country.php?ip=" . $ip));
         if ($country != 'XX') {
             return $country;
         }
     } catch (Exception $e) {
     }
     return 'XX';
 }
开发者ID:W1zzardTPU,项目名称:XenForo_TPUDetectSpamReg,代码行数:34,代码来源:IPCountry.php

示例4: 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

示例5: init

 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if (!extension_loaded('geoip')) {
         throw new \Exception('Расширение GeoIP  недоступно');
     }
     if (!geoip_db_avail(GEOIP_COUNTRY_EDITION)) {
         \Yii::error(\Yii::t('yii', 'GeoIP country database not available.'), __METHOD__);
     }
     if (!geoip_db_avail(GEOIP_CITY_EDITION_REV0) && !geoip_db_avail(GEOIP_CITY_EDITION_REV1)) {
         \Yii::error(\Yii::t('yii', 'GeoIP city database not available.'), __METHOD__);
     }
 }
开发者ID:hysdop,项目名称:YobaCMS,代码行数:16,代码来源:GeoIP.php

示例6: getDatabaseVersions

 public function getDatabaseVersions()
 {
     $dbs = array('GEOIP_COUNTRY_EDITION' => GEOIP_COUNTRY_EDITION, 'GEOIP_REGION_EDITION_REV0' => GEOIP_REGION_EDITION_REV0, 'GEOIP_CITY_EDITION_REV0' => GEOIP_CITY_EDITION_REV0, 'GEOIP_ORG_EDITION' => GEOIP_ORG_EDITION, 'GEOIP_ISP_EDITION' => GEOIP_ISP_EDITION, 'GEOIP_CITY_EDITION_REV1' => GEOIP_CITY_EDITION_REV1, 'GEOIP_REGION_EDITION_REV1' => GEOIP_REGION_EDITION_REV1, 'GEOIP_PROXY_EDITION' => GEOIP_PROXY_EDITION, 'GEOIP_ASNUM_EDITION' => GEOIP_ASNUM_EDITION, 'GEOIP_NETSPEED_EDITION' => GEOIP_NETSPEED_EDITION, 'GEOIP_DOMAIN_EDITION' => GEOIP_DOMAIN_EDITION);
     $res = array();
     foreach ($dbs as $name => $id) {
         if (!\geoip_db_avail($id)) {
             continue;
         }
         $info = \geoip_database_info($id);
         $x = explode(' ', $info);
         $res[] = array('name' => $name, 'file' => \geoip_db_filename($id), 'date' => $x[1], 'version' => $x[0]);
     }
     return $res;
 }
开发者ID:martinlindhe,项目名称:core3,代码行数:14,代码来源:GeoIp.php

示例7: canInstall

 public function canInstall(&$message = null)
 {
     if (is_callable('geoip_db_avail')) {
         if (geoip_db_avail(GEOIP_COUNTRY_EDITION) || geoip_db_avail(GEOIP_REGION_EDITION_REV0) || geoip_db_avail(GEOIP_CITY_EDITION_REV0) || geoip_db_avail(GEOIP_CITY_EDITION_REV1) || geoip_db_avail(GEOIP_REGION_EDITION_REV1)) {
             return true;
         } else {
             $this->installError = 'GeoIP Database missing';
             return false;
         }
     } else {
         $this->installError = 'PECL GeoIP extension not avaialble';
         return false;
     }
 }
开发者ID:norv,项目名称:EosAlpha,代码行数:14,代码来源:main.php

示例8: getGeoIpVersion

 /**
  * Get GeoIp Version release
  * Return an array with keys "country" & "city"
  * @access public
  * @return array
  */
 public function getGeoIpVersion()
 {
     $return = array('country' => '-', 'city' => '-', 'local' => '-');
     // let's see the version of local .dat file
     $geoipPath = $this->config->resources->geoip->path;
     $geoipVersion = explode(" ", Dot_Geoip_Country::geoipDatabaseInfo($geoipPath));
     $return['local'] = $geoipVersion[0] . ' ' . Dot_Kernel::TimeFormat($geoipVersion[1]);
     // do we have geoIP server-wide ?
     if (function_exists('geoip_database_info')) {
         if (geoip_db_avail(GEOIP_COUNTRY_EDITION)) {
             $info = explode(" ", geoip_database_info(GEOIP_COUNTRY_EDITION));
             $return['country'] = $info[0] . ' ' . Dot_Kernel::TimeFormat($info[1]);
         }
     }
     return $return;
 }
开发者ID:sandeepdwarkapuria,项目名称:dotkernel,代码行数:22,代码来源:System.php

示例9: getTimezone

 /**
  * 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;
 }
开发者ID:opensolutions,项目名称:oss-framework,代码行数:24,代码来源:GeoIP.php

示例10: __construct

 public function __construct($arDBRecord = false)
 {
     parent::__construct($arDBRecord);
     if (!$arDBRecord) {
         if (function_exists("geoip_db_avail")) {
             $this->country_avail = geoip_db_avail(GEOIP_COUNTRY_EDITION);
             $this->city_avail = geoip_db_avail(GEOIP_CITY_EDITION_REV0) || geoip_db_avail(GEOIP_CITY_EDITION_REV1);
             $this->is_installed = $this->country_avail || $this->city_avail;
         }
         $this->charset = "iso-8859-1";
     } else {
         if (array_key_exists("XPOST", $arDBRecord)) {
             $this->postal_code = $arDBRecord["XPOST"];
         }
         if (array_key_exists("XLAT", $arDBRecord)) {
             $this->latitude = $arDBRecord["XLAT"];
         }
         if (array_key_exists("XLON", $arDBRecord)) {
             $this->longitude = $arDBRecord["XLON"];
         }
     }
 }
开发者ID:rasuldev,项目名称:torino,代码行数:22,代码来源:geoip_extension.php

示例11: getCountry

 public static function getCountry($allow_countory, $deny_countory)
 {
     // Block countory via Geolocation
     $country_code = false;
     if (isset($_SERVER['HTTP_CF_IPCOUNTRY'])) {
         // CloudFlareを使用している場合、そちらのGeolocationを読み込む
         // https://www.cloudflare.com/wiki/IP_Geolocation
         $country_code = $_SERVER['HTTP_CF_IPCOUNTRY'];
     } else {
         if (isset($_SERVER['GEOIP_COUNTRY_CODE'])) {
             // サーバーが$_SERVER['GEOIP_COUNTRY_CODE']を出力している場合
             // Apache : http://dev.maxmind.com/geoip/mod_geoip2
             // nginx : http://wiki.nginx.org/HttpGeoipModule
             // cherokee : http://www.cherokee-project.com/doc/config_virtual_servers_rule_types.html
             $country_code = $_SERVER['GEOIP_COUNTRY_CODE'];
         } else {
             if (function_exists('geoip_db_avail') && geoip_db_avail(GEOIP_COUNTRY_EDITION) && function_exists('geoip_region_by_name')) {
                 // それでもダメな場合は、phpのgeoip_region_by_name()からGeolocationを取得
                 // http://php.net/manual/en/function.geoip-region-by-name.php
                 $geoip = geoip_region_by_name(REMOTE_ADDR);
                 $country_code = $geoip['country_code'];
                 if (DEBUG) {
                     $info[] = !empty($geoip['country_code']) ? 'GeoIP is usable. Your country code from IP is inferred <var>' . $geoip['country_code'] . '</var>.' : 'GeoIP is NOT usable. Maybe database is not installed. Please check <a href="http://www.maxmind.com/app/installation?city=1" rel="external">GeoIP Database Installation Instructions</a>';
                 }
             } else {
                 if (function_exists('apache_note')) {
                     // Apacheの場合
                     $country_code = apache_note('GEOIP_COUNTRY_CODE');
                 }
             }
         }
     }
     if (DEBUG) {
         // 使用可能かをチェック
         $info[] = isset($country_code) && !empty($country_code) ? 'Your country code from IP is inferred <var>' . $country_code . '</var>.' : 'Seems Geolocation is not available. <var>' . $deny_countory . '</var> value and <var>' . $allow_countory . '</var> value is ignoled.';
     }
     return $country_code;
 }
开发者ID:logue,项目名称:pukiwiki_adv,代码行数:38,代码来源:Country.php

示例12: checkEnv

 /**
  * 環境変数のチェック
  */
 public static function checkEnv($env)
 {
     global $deny_countory, $allow_countory;
     // 国別設定
     $country_code = '';
     if (isset($env['HTTP_CF_IPCOUNTRY'])) {
         // CloudFlareを使用している場合、そちらのGeolocationを読み込む
         // https://www.cloudflare.com/wiki/IP_Geolocation
         $country_code = $env['HTTP_CF_IPCOUNTRY'];
     } else {
         if (isset($env['GEOIP_COUNTRY_CODE'])) {
             // サーバーが$_SERVER['GEOIP_COUNTRY_CODE']を出力している場合
             // Apache : http://dev.maxmind.com/geoip/mod_geoip2
             // nginx : http://wiki.nginx.org/HttpGeoipModule
             // cherokee : http://www.cherokee-project.com/doc/config_virtual_servers_rule_types.html
             $country_code = $env['GEOIP_COUNTRY_CODE'];
         } else {
             if (function_exists('geoip_db_avail') && geoip_db_avail(GEOIP_COUNTRY_EDITION) && function_exists('geoip_region_by_name')) {
                 // それでもダメな場合は、phpのgeoip_region_by_name()からGeolocationを取得
                 // http://php.net/manual/en/function.geoip-region-by-name.php
                 $geoip = geoip_region_by_name(REMOTE_ADDR);
                 $country_code = $geoip['country_code'];
                 $info[] = !empty($geoip['country_code']) ? 'GeoIP is usable. Your country code from IP is inferred <var>' . $geoip['country_code'] . '</var>.' : 'GeoIP is NOT usable. Maybe database is not installed. Please check <a href="http://www.maxmind.com/app/installation?city=1" rel="external">GeoIP Database Installation Instructions</a>';
             } else {
                 if (function_exists('apache_note')) {
                     // Apacheの場合
                     $country_code = apache_note('GEOIP_COUNTRY_CODE');
                 }
             }
         }
     }
     // 使用可能かをチェック
     if (!isset($country_code) || empty($country_code)) {
         $info[] = 'Seems Geolocation is not available. <var>$deny_countory</var> value and <var>$allow_countory</var> value is ignoled.';
     } else {
         $info[] = 'Your country code from IP is inferred <var>' . $country_code . '</var>.';
         if (isset($deny_countory) && !empty($deny_countory)) {
             if (in_array($country_code, $deny_countory)) {
                 die('Sorry, access from your country(' . $geoip['country_code'] . ') is prohibited.');
                 exit;
             }
         }
         if (isset($allow_countory) && !empty($allow_countory)) {
             if (!in_array($country_code, $allow_countory)) {
                 die('Sorry, access from your country(' . $geoip['country_code'] . ') is prohibited.');
                 exit;
             }
         }
     }
     // INI_FILE: $agents:  UserAgentの識別
     $user_agent = $matches = array();
     $user_agent['agent'] = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
     // unset(${$ua}, $_SERVER[$ua], $HTTP_SERVER_VARS[$ua], $ua);	// safety
     if (empty($user_agent['agent'])) {
         die;
     }
     // UAが取得できない場合は処理を中断
     foreach (self::loadConfig('profile.ini.php') as $agent) {
         if (preg_match($agent['pattern'], $user_agent['agent'], $matches)) {
             $user_agent = array('profile' => isset($agent['profile']) ? $agent['profile'] : null, 'name' => isset($matches[1]) ? $matches[1] : null, 'vers' => isset($matches[2]) ? $matches[2] : null);
             break;
         }
     }
     $ua_file = self::add_homedir($user_agent['profile'] . '.ini.php');
     if ($ua_file) {
         require $ua_file;
     }
     define('UA_NAME', isset($user_agent['name']) ? $user_agent['name'] : null);
     define('UA_VERS', isset($user_agent['vers']) ? $user_agent['vers'] : null);
     define('UA_CSS', isset($user_agent['css']) ? $user_agent['css'] : null);
     // HTTP_X_REQUESTED_WITHヘッダーで、ajaxによるリクエストかを判別
     define('IS_AJAX', isset($env['HTTP_X_REQUESTED_WITH']) && strtolower($env['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' || isset($vars['ajax']));
 }
开发者ID:logue,项目名称:pukiwiki_adv,代码行数:76,代码来源:Utility.php

示例13: error

 if (mb_strlen($post['subject']) > 100) {
     error(sprintf($config['error']['toolong'], 'subject'));
 }
 if (!$mod && mb_strlen($post['body']) > $config['max_body']) {
     error($config['error']['toolong_body']);
 }
 if (mb_strlen($post['password']) > 20) {
     error(sprintf($config['error']['toolong'], 'password'));
 }
 wordfilters($post['body']);
 $post['body'] = escape_markup_modifiers($post['body']);
 if ($mod && isset($post['raw']) && $post['raw']) {
     $post['body'] .= "\n<tinyboard raw html>1</tinyboard>";
 }
 if ($config['country_flags']) {
     if (!geoip_db_avail(GEOIP_COUNTRY_EDITION)) {
         error('GeoIP not available: ' . geoip_db_filename(GEOIP_COUNTRY_EDITION));
     }
     if ($country_code = @geoip_country_code_by_name($_SERVER['REMOTE_ADDR'])) {
         if (!in_array(strtolower($country_code), array('eu', 'ap', 'o1', 'a1', 'a2'))) {
             $post['body'] .= "\n<tinyboard flag>" . strtolower($country_code) . "</tinyboard>" . "\n<tinyboard flag alt>" . @geoip_country_name_by_name($_SERVER['REMOTE_ADDR']) . "</tinyboard>";
         }
     }
 }
 if (mysql_version() >= 50503) {
     $post['body_nomarkup'] = $post['body'];
     // Assume we're using the utf8mb4 charset
 } else {
     // MySQL's `utf8` charset only supports up to 3-byte symbols
     // Remove anything >= 0x010000
     $chars = preg_split('//u', $post['body'], -1, PREG_SPLIT_NO_EMPTY);
开发者ID:carriercomm,项目名称:Tinyboard,代码行数:31,代码来源:post.php

示例14: getRecentActivity

 /**
  * 
  * Gets a array with the information about the sessions the user is logged in at the time
  * ordened from the last to the first
  * @param big int $uid
  */
 public function getRecentActivity($uid)
 {
     $this->meta_gc($uid);
     $sessionsList = $this->listRecentSessionsMeta($uid);
     $activity = array();
     foreach ($sessionsList as $oneSession) {
         $lastActivityInfo = $this->_cache->load($this->_lastActivityPrefix . $oneSession['session']);
         if (is_array($lastActivityInfo)) {
             $lastActivityInfo['session'] = $oneSession['session'];
             $lastActivityInfo['status'] = $oneSession['status'];
             if (extension_loaded("geoip") && geoip_db_avail(GEOIP_COUNTRY_EDITION) && isset($lastActivityInfo['remote_addr'])) {
                 $lastActivityInfo['geo'] = @geoip_record_by_name($lastActivityInfo['remote_addr']);
             } else {
                 $lastActivityInfo['geo'] = false;
             }
             if (isset($lastActivityInfo['request_time']) && $lastActivityInfo['request_time'] > (int) $_SERVER['REQUEST_TIME'] - self::RECENT_ACCESS_SECONDS) {
                 $activity[] = $lastActivityInfo;
             }
         }
     }
     return $activity;
 }
开发者ID:henvic,项目名称:MediaLab,代码行数:28,代码来源:Session.php

示例15: isISPDatabaseAvailable

 /**
  * Returns true if the PECL module can detect an ISP database.
  *
  * @return bool
  */
 public static function isISPDatabaseAvailable()
 {
     return geoip_db_avail(GEOIP_ISP_EDITION);
 }
开发者ID:parruc,项目名称:piwik,代码行数:9,代码来源:Pecl.php


注:本文中的geoip_db_avail函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。