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


PHP geoip_country_code_by_name函数代码示例

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


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

 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;
 }
开发者ID:rogatnev-nikita,项目名称:cloudinterpreter,代码行数:30,代码来源:frontpage.php

示例3: blockCountryView

 public function blockCountryView(Result $result)
 {
     $result->getParam('request');
     $allow = $this->preferences->get('foolfuuka.plugins.geoip_region_lock.allow_view');
     $disallow = $this->preferences->get('foolfuuka.plugins.geoip_region_lock.disallow_view');
     if ($allow || $disallow) {
         $country = strtolower(\geoip_country_code_by_name($request->getClientIp()));
     }
     if ($allow) {
         $allow = explode(',', $allow);
         foreach ($allow as $al) {
             if (strtolower(trim($al)) == $country) {
                 return null;
             }
         }
         $result->set(new Response(_i('Not available in your country.'), 403));
         return;
     }
     if ($disallow) {
         $disallow = explode(',', $disallow);
         foreach ($disallow as $disal) {
             if (strtolower(trim($disal)) == $country) {
                 $result->set(new Response(_i('Not available in your country.'), 403));
                 throw new NotFoundHttpException();
             }
         }
     }
     return null;
 }
开发者ID:procod3R,项目名称:FoolFuuka,代码行数:29,代码来源:geoip_region_lock.php

示例4: dmn_getcountry

function dmn_getcountry($mnip, &$countrycode)
{
    $mnipalone = substr($mnip, 0, strpos($mnip, ":"));
    $res = geoip_country_name_by_name($mnipalone);
    $countrycode = strtolower(geoip_country_code_by_name($mnipalone));
    return $res;
}
开发者ID:elbereth,项目名称:dashninja-ctl,代码行数:7,代码来源:dmnctl.script.inc.php

示例5: isThirdPayOn

 public function isThirdPayOn()
 {
     $countryCode = geoip_country_code_by_name($_SERVER['REMOTE_ADDR']);
     $log_array = array('type' => 'geoip country code_by name', 'msg' => $countryCode);
     log_message('gash', json_encode($log_array));
     echo $countryCode;
 }
开发者ID:helenseo,项目名称:pay,代码行数:7,代码来源:web_config.php

示例6: execute

 public function execute($sub)
 {
     global $wgOut, $wgRequest;
     global $wgLandingPageBase, $wgChapterLandingPages, $wgLandingPageDefaultTarget;
     $lang = preg_match('/^[A-Za-z-]+$/', $wgRequest->getVal('lang')) ? $wgRequest->getVal('lang') : 'en';
     $utm_source = $wgRequest->getVal('utm_source');
     $utm_medium = $wgRequest->getVal('utm_medium');
     $utm_campaign = $wgRequest->getVal('utm_campaign');
     $referrer = $wgRequest->getHeader('referer');
     $target = $wgRequest->getVal('target', null);
     if (!$target) {
         $target = $wgLandingPageDefaultTarget;
     }
     $tracking = '?' . wfArrayToCGI(array('utm_source' => "{$utm_source}", 'utm_medium' => "{$utm_medium}", 'utm_campaign' => "{$utm_campaign}", 'referrer' => "{$referrer}", 'target' => "{$target}"));
     $ip = $wgRequest->getVal('ip') ? $wgRequest->getVal('ip') : wfGetIP();
     if (IP::isValid($ip)) {
         $country = geoip_country_code_by_name($ip);
         if (is_string($country) && array_key_exists($country, $wgChapterLandingPages)) {
             $wgOut->redirect($this->getDestination($utm_source) . '/' . $wgChapterLandingPages[$country] . $tracking);
             return;
         }
     }
     // No valid IP or chapter page - let's just go for the passed in url or our fallback
     if (Http::isValidURI($target)) {
         $wgOut->redirect($target . '/' . $lang . $tracking);
         return;
     } else {
         $wgOut->redirect($wgLandingPageBase . $target . '/' . $lang . $tracking);
     }
 }
开发者ID:realsoc,项目名称:mediawiki-extensions,代码行数:30,代码来源:GeoLite_body.php

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

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

示例9: execute

 function execute($par)
 {
     global $wgRequest, $wgOut, $wgFundraiserLPDefaults;
     // Set the country parameter
     $country = $wgRequest->getVal('country');
     // If no country was passed do a GeoIP lookup
     if (!$country) {
         if (function_exists('geoip_country_code_by_name')) {
             $ip = wfGetIP();
             if (IP::isValid($ip)) {
                 $country = geoip_country_code_by_name($ip);
             }
         }
     }
     // If country still isn't set, set it to the default
     if (!$country) {
         $country = $wgFundraiserLPDefaults['country'];
     }
     $params = array('country' => $country);
     // Pass any other params that are set
     $excludeKeys = array('country', 'title');
     foreach ($wgRequest->getValues() as $key => $value) {
         // Skip the required variables
         if (!in_array($key, $excludeKeys)) {
             $params[$key] = $value;
         }
     }
     // Redirect to FundraiserLandingPage
     $wgOut->redirect($this->getTitleFor('FundraiserLandingPage')->getLocalUrl($params));
 }
开发者ID:realsoc,项目名称:mediawiki-extensions,代码行数:30,代码来源:FundraiserRedirector.body.php

示例10: onPreLogin

 public function onPreLogin(PlayerPreLoginEvent $event)
 {
     $p = $event->getPlayer();
     $i = $p->getAddress();
     $co = geoip_country_code_by_name($i);
     if ($this->c[$co]) {
         $p->close("", $this->reason[$co]);
         $event->setCancelled(true);
     }
 }
开发者ID:MrDoni98,项目名称:CountryBlocker,代码行数:10,代码来源:CountryBlocker.php

示例11: getCountry

 public function getCountry($visitorAddress)
 {
     if (!function_exists("geoip_country_code_by_name")) {
         // @codeCoverageIgnoreStart
         throw new \InvalidArgumentException("It seems, the geo-ip extension is not installed for php.");
         // @codeCoverageIgnoreEnd
     }
     $counrtyCode = @\geoip_country_code_by_name($visitorAddress);
     return $counrtyCode;
 }
开发者ID:azine,项目名称:geoblocking-bundle,代码行数:10,代码来源:DefaultLookupAdapter.php

示例12: login_admin

 function login_admin()
 {
     $login_success = null;
     if (isset($_POST['login'])) {
         $login = $_POST['login'];
         $this->form_validation->set_rules('login[member_code]', 'Email / Member ID', 'required');
         $this->form_validation->set_rules('login[password]', 'required');
         if ($this->form_validation->run() == FALSE) {
             $login_success = false;
             $this->nativesession->set_flashdata('login_status', '<div class="alert alert-danger">' . validation_errors() . '</div>');
             $this->index();
         } else {
             // $data = array('member_code' => $login[ 'member_code' ]);
             $potential_user = $this->admin_login_model->get_user_existing_data($login['member_code']);
             if ($potential_user) {
                 $this->load->library('PBKDF2');
                 $admin = $potential_user;
                 $pbkdf2 = new PBKDF2();
                 if ($pbkdf2->validatePassword($login['password'], $admin['password'])) {
                     if ($admin['status'] == 'active') {
                         $login_success = true;
                         if (isset($login['remember_me'])) {
                             // @TODO remember me mechanism
                         }
                         $this->nativesession->set(array('is_logged_in' => true, 'is_gan_admin_logged_in' => true, 'member_id' => $admin['id'], 'member_code' => $admin['member_code'], 'account_type' => $admin['account_type']));
                         // $country_code = function_exists( 'geoip_country_code_by_name' ) ? geoip_country_code_by_name( $_SERVER[ 'REMOTE_ADDR' ] ) : '';
                         $member_id = (string) $admin['id'];
                         $member_data = array('last_login_date' => date('Y-m-d H:i:s'), 'last_login_ip' => $_SERVER['REMOTE_ADDR'], 'last_login_country' => function_exists('geoip_country_code_by_name') ? geoip_country_code_by_name($_SERVER['REMOTE_ADDR']) : '');
                         $this->admin_login_model->update_member($member_id, $member_data);
                         redirect(base_url('admin/home'));
                     } else {
                         if ($member['status'] == 'inactive') {
                             $this->nativesession->set_flashdata('login_status', '<div class="alert alert-danger">It seems that your account is inactive. please contact your administrator.</div>');
                             $login_success = false;
                             redirect(base_url('login'));
                         } else {
                             $this->nativesession->set_flashdata('login_status', '<div class="alert alert-danger">Your account is suspended, please contact administrator.</div>');
                             $login_success = false;
                             redirect(base_url('admin/login'));
                         }
                     }
                 } else {
                     $this->nativesession->set_flashdata('login_status', '<div class="alert alert-danger">Incorrect Email/member id or password ' . $potential_user . '.</div>');
                     $login_success = false;
                     redirect(base_url('admin/login'));
                 }
             } else {
                 $this->nativesession->set_flashdata('login_status', '<div class="alert alert-danger">Incorrect Member ID or Password : Acces Denied.</div>');
                 $login_success = false;
                 redirect(base_url('admin/login'));
             }
         }
     }
 }
开发者ID:kobe8bird,项目名称:gan,代码行数:54,代码来源:admin_login.php

示例13: checkGeo

 public function checkGeo()
 {
     $targetGeo = json_decode($this->target_geo);
     if ($targetGeo) {
         $clientCountry = strtolower(geoip_country_code_by_name(getClientIp()));
         if (in_array($clientCountry, $targetGeo)) {
             return true;
         }
     }
     return false;
 }
开发者ID:huycao,项目名称:yoplatform,代码行数:11,代码来源:AdBaseModel.php

示例14: getCountryCode

 public function getCountryCode()
 {
     if (empty($this->countryCode) && !YII_DEBUG) {
         if (empty(Yii::app()->request->cookies['country_code'])) {
             $this->countryCode = geoip_country_code_by_name($this->getUserHostAddress());
             Yii::app()->request->cookies['country_code'] = new CHttpCookie('country_code', $this->countryCode, array('expire' => time() + 86400));
         } else {
             $this->countryCode = Yii::app()->request->cookies['country_code'];
         }
     }
     return $this->countryCode;
 }
开发者ID:maduhu,项目名称:openbay,代码行数:12,代码来源:AHttpRequest.php

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


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