本文整理汇总了PHP中geoip_country_code_by_addr函数的典型用法代码示例。如果您正苦于以下问题:PHP geoip_country_code_by_addr函数的具体用法?PHP geoip_country_code_by_addr怎么用?PHP geoip_country_code_by_addr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了geoip_country_code_by_addr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: plugin_geoip_flag
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);
}
示例2: setlang
function setlang()
{
$CFG =& load_class('Config');
//$OUT = &load_class('Output');
$CFG->load('site');
$a = explode('/', $_SERVER["REQUEST_URI"]);
if (sizeof($a) > 0) {
$lang = $a[1];
if ($CFG->item('folder') == true) {
$lang = $a[2];
}
switch ($lang) {
case 'ru':
$CFG->set_item('language', "ru");
break;
case 'en':
$CFG->set_item('language', "en");
break;
default:
include BASEPATH . 'libraries/third_party/Geoip.php';
$country = geoip_country_code_by_addr(open_geo(), $_SERVER['REMOTE_ADDR']);
switch ($country) {
case 'RU':
$CFG->set_item('language', "ru");
break;
case 'UA':
$CFG->set_item('language', "ru");
break;
default:
$CFG->set_item('language', "en");
break;
}
}
}
}
示例3: getGeoIpLocation
/**
* 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;
}
示例4: testgeoipdatabase
function testgeoipdatabase($type, $flags, $msg, $numlookups)
{
$gi = geoip_open($this->dbfilename[$type], $flags);
if ($gi == null) {
print "error: " . $this->dbfilename[$type] . " does not exist\n";
return;
}
$t1 = $this->ftime();
$i4 = 0;
for ($i2 = 0; $i2 < $numlookups; $i2++) {
switch ($type) {
case GEOIP_COUNTRY_DATABASE:
geoip_country_code_by_addr($gi, $this->randomipaddress());
break;
case GEOIP_REGION_DATABASE:
geoip_region_by_addr($gi, $this->randomipaddress());
break;
case GEOIP_CITY_DATABASE:
GeoIP_record_by_addr($gi, $this->randomipaddress());
break;
}
}
$t2 = $this->ftime();
$t3 = $t2 - $t1;
print $msg . "\n";
print $numlookups . " lookups made in " . $t3 . " seconds \n";
geoip_close($gi);
}
示例5: onPostDispatchIndexController
public function onPostDispatchIndexController(Enlight_Event_EventArgs $arguments)
{
$controller = $arguments->getSubject();
$view = $controller->View();
$view->addTemplateDir($this->Path() . 'Views/');
$shopLang = Shopware()->Front()->Request()->getCookie('shopLang');
// $ip = $_SERVER['REMOTE_ADDR'];
$ip = '195.149.248.130';
//BG
// $ip = '194.50.69.124'; //DE
// $ip = '211.156.198.82'; //CN
$gi = geoip_open(__DIR__ . '/GeoIp/db/GeoIP.dat', GEOIP_STANDARD);
$countryCode = geoip_country_code_by_addr($gi, $ip);
geoip_close($gi);
if ($shopLang != strtolower($countryCode)) {
$shopLang = strtolower($countryCode);
Shopware()->Front()->Response()->setCookie('shopLang', $shopLang, 0);
$builder = Shopware()->Container()->get('dbal_connection')->createQueryBuilder();
$shopId = $builder->select('scs.id')->from('s_core_locales', 'scl')->innerJoin('scl', 's_core_shops', 'scs', 'scl.id = scs.locale_id')->where('scl.locale LIKE ?')->setParameter(0, $shopLang . '%')->execute()->fetch();
if ($shopId) {
$view->extendsTemplate('frontend/index/change_shop.tpl');
$view->assign(array('shopId' => $shopId['id']));
}
}
}
示例6: readM
function readM()
{
include 'geoip.inc';
$gi = geoip_open('resources/GeoIP.dat', GEOIP_STANDARD);
$country_code = geoip_country_code_by_addr($gi, $_SERVER['REMOTE_ADDR']);
//$this->data['country_code'] = $country_code;
$country_name = geoip_country_name_by_addr($gi, $_SERVER['REMOTE_ADDR']);
//$this->data['country_name'] = $country_name;
// close the database
geoip_close($gi);
$visit = array('id' => NULL, 'negara' => $country_name, 'visit' => 'news');
$this->model_visit->add($visit);
$id = $this->uri->segment(4);
if ($id == "cpagenews") {
$bh = $this->uri->segment(6);
redirect('user/cpagenews/ubahBhs/' . $this->uri->segment(6));
}
$data['title'] = "news";
$this->load->view('user/vheader', $data);
$bhs = $this->session->userdata('EN');
$data['gambar'] = $this->model_gambar->getGmb();
$data['berit'] = $this->model_berita->getByMore($id);
$data['pengunjung'] = $this->model_conter->counAll();
$data['news'] = $this->model_berita->getSlideNews($bhs);
$this->load->view('user/vmenu');
$this->load->view('user/frontend/page/vreadmore', $data);
$this->load->view('user/vfooter');
}
示例7: wpgeoip_redirect
function wpgeoip_redirect()
{
if (get_option('wpgeoip_no_redirect', 0) == 1 and isset($_GET['noredirect'])) {
return false;
}
require_once 'geoip.inc';
//open geoip binary database
$gi = geoip_open(plugin_dir_path(__FILE__) . 'GeoIP.dat', GEOIP_STANDARD);
global $wpdb;
global $wp_query;
global $post;
$prefix = $wpdb->prefix;
$postID = $post->ID;
$catID = intval($wp_query->query_vars['cat']);
$isHome = is_home();
$the_page_name = '';
//get user country
$countryCode = geoip_country_code_by_addr($gi, WPGeoIP_getIP());
//sitewide rule
$rs_redirect = $wpdb->get_row("SELECT `targetURL` FROM `" . $prefix . "grules` WHERE `countryID` = '{$countryCode}' \n\t\t\t\t\t\t\tAND `postID` = 999999");
if (isset($rs_redirect) and count($rs_redirect)) {
$the_page_name = get_the_title($postID);
$wpdb->query("INSERT INTO wpgeoip_log VALUES (null, 'SITEWIDE Redirect', 'Redirecting Country <strong>" . $countryCode . "</strong> to " . $rs_redirect->targetURL . "')");
print '<meta http-equiv="refresh" content="0;url=' . $rs_redirect->targetURL . '"/>';
exit;
}
//redirect if any rule for this country
if ($postID != 0) {
$rs_redirect = $wpdb->get_row("SELECT `targetURL` FROM `" . $prefix . "grules` WHERE `countryID` = '{$countryCode}' \n\t\t\t\t\t\t\tAND `postID` = {$postID}");
$the_page_name = get_the_title($postID);
}
if ($catID != 0) {
$rs_redirect = $wpdb->get_row("SELECT `targetURL` FROM `" . $prefix . "grules` WHERE `countryID` = '{$countryCode}' \n\t\t\t\t\t\t\tAND `catID` = {$catID}");
$the_page_name = 'Category : ' . get_the_category_by_ID($catID);
}
if ($isHome) {
$rs_redirect = $wpdb->get_row("SELECT `targetURL` FROM `" . $prefix . "grules` WHERE `countryID` = '{$countryCode}' \n\t\t\t\t\t\t\tAND `home_rule` = 1");
$the_page_name = 'Homepage';
}
if (!$rs_redirect) {
//NOTHING TO DO
#$wpdb->query("INSERT INTO wpgeoip_log VALUES (null, 'Redirect', 'Nothing to do. No rules for Country <strong>".$countryCode."</strong>')");
}
if (isset($rs_redirect) and count($rs_redirect)) {
$wpdb->query("INSERT INTO wpgeoip_log VALUES (null, 'Redirect <em>" . $the_page_name . "</em>', 'Redirecting Country <strong>" . $countryCode . "</strong> to " . $rs_redirect->targetURL . "')");
print '<meta http-equiv="refresh" content="0;url=' . $rs_redirect->targetURL . '"/>';
exit;
} else {
//CHECK COUNTRIES WITHOUT REDIRECT RULES
$mass_redirect_enabled = get_option('wpgeoip_mass_redirect');
if ($mass_redirect_enabled != "0") {
$mass_url = get_option('wpgeoip_mass_url');
$wpdb->query("INSERT INTO wpgeoip_log VALUES (null, 'Mass Redirect', 'Redirecting Country <strong>" . $countryCode . "</strong> to " . $rs_redirect->targetURL . "')");
print '<meta http-equiv="refresh" content="0;url=' . $mass_url . '"/>';
exit;
} else {
//NOTHING TO DO AGAINM
}
}
}
示例8: index
function index()
{
$ip = $_SERVER['REMOTE_ADDR'];
$masuk = TRUE;
$msk = TRUE;
$mskC = TRUE;
$today = date('Y-m-d');
include 'geoip.inc';
$gi = geoip_open('resources/GeoIP.dat', GEOIP_STANDARD);
$country_code = geoip_country_code_by_addr($gi, $_SERVER['REMOTE_ADDR']);
//$this->data['country_code'] = $country_code;
$country_name = geoip_country_name_by_addr($gi, $_SERVER['REMOTE_ADDR']);
//$this->data['country_name'] = $country_name;
// close the database
geoip_close($gi);
$visit = array('id' => NULL, 'negara' => $country_name, 'visit' => 'gallery');
$this->model_visit->add($visit);
$data['title'] = "gallery";
$bhs = $this->session->userdata('EN');
$data['pengunjung'] = $this->model_conter->counAll();
$data['galeri'] = $this->model_galery->getBahasa($bhs);
$data['gambar'] = $this->model_gambar->getGmb();
$this->load->view('user/vheader', $data);
$this->load->view('user/vmenu');
$this->load->view('user/frontend/page/vgallery');
$this->load->view('user/vfooter');
}
示例9: GetCurrencyByIP
/**
* Fetch the currency code to use based on the current visitors IP address. This function will perform a
* GeoIP based lookup of the current visitors IP address and if possible, find a matching currency.
*
* @return mixed False if a currency cannot be found, else the currency ID if a matching currency was found.
*/
function GetCurrencyByIP()
{
require_once ISC_BASE_PATH."/lib/geoip/geoip.php";
$geoIp = @geoip_open(ISC_BASE_PATH."/lib/geoip/GeoIP.dat", GEOIP_STANDARD);
if(!$geoIp) {
return false;
}
$code = geoip_country_code_by_addr($geoIp, GetIP());
if(!$code) {
return false;
}
$query = "
SELECT currencyid
FROM [|PREFIX|]currencies cu
LEFT JOIN [|PREFIX|]countries co ON cu.currencycountryid = co.countryid
LEFT JOIN (
SELECT r.couregid, c.countryiso2
FROM [|PREFIX|]countries c
JOIN [|PREFIX|]country_regions r ON c.countrycouregid = r.couregid
) cr ON cu.currencycouregid = cr.couregid
WHERE
(
co.countryiso2 = '" . $GLOBALS['ISC_CLASS_DB']->Quote($code) . "' OR
cr.countryiso2 = '" . $GLOBALS['ISC_CLASS_DB']->Quote($code) . "'
) AND
cu.currencystatus = 1
LIMIT 1
";
return $GLOBALS['ISC_CLASS_DB']->FetchOne($query, 'currencyid');
}
示例10: GetCountry
function GetCountry($bot_ip)
{
$GI = geoip_open('includes/GeoIP.dat', GEOIP_STANDARD);
$bot_country = geoip_country_code_by_addr($GI, $bot_ip);
geoip_close($GI);
return $bot_country;
}
示例11: add_info
public function add_info($uuid, $release)
{
// get ip from remote address
$ip = $_SERVER['REMOTE_ADDR'];
// get geodata
$gi = geoip_open("/usr/share/GeoIP/GeoIP.dat", GEOIP_STANDARD);
// get country code from ip
$country_code = geoip_country_code_by_addr($gi, $ip);
// get country name from ip
$country_name = geoip_country_name_by_addr($gi, $ip);
try {
// get connession
$conn = new PDO("mysql:host=" . $GLOBALS['$dbhost'] . ";dbname=" . $GLOBALS['$dbname'] . "", $GLOBALS['$dbuser'], $GLOBALS['$dbpass']);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// insert query
$sql = "REPLACE INTO phone_home_tb (uuid,\n release_tag,\n ip,\n country_code,\n country_name,\n reg_date)\n VALUES (:uuid,\n :release,\n :ip,\n :country_code,\n :country_name,\n NOW())";
// prepare statement
$stmt = $conn->prepare($sql);
// execute query
$stmt->execute(array(':uuid' => $uuid, ':release' => $release, ':ip' => $ip, ':country_code' => $country_code, ':country_name' => $country_name));
// close connession
$conn = null;
} catch (PDOException $e) {
echo $e->getMessage();
}
}
示例12: getCountryCodeFromIP
/**
* Return in lower case the country code from an ip
*
* @param $ip IP to scan
* @return string Country code (two letters)
*/
function getCountryCodeFromIP($ip)
{
if (empty($this->gi))
{
return '';
}
return strtolower(geoip_country_code_by_addr($this->gi, $ip));
}
示例13: ip2cc
function ip2cc($ip)
{
static $gi = null;
if ($gi === null) {
$gi = geoip_open(__DIR__ . '/geoip/GeoIP.dat', GEOIP_STANDARD);
}
return geoip_country_code_by_addr($gi, $ip);
}
示例14: get_country
function get_country()
{
include "application/helpers/geoip/files/geoip.inc";
$gi = geoip_open("application/helpers/geoip/files/GeoIP.dat", GEOIP_STANDARD);
$country_code = geoip_country_code_by_addr($gi, $_SERVER['HTTP_X_REAL_IP']);
geoip_close($gi);
return $country_code;
}
示例15: country_code
/**
* @param null $address
* @return bool|string
*/
public function country_code($address = null)
{
$countryCode = geoip_country_code_by_addr($this->gi, $address);
if ($countryCode == null) {
$countryCode = '-';
}
return $countryCode;
}