Primero crea un archivo con el nombre: Geoplugin.class.php
en el coloca lo siguiente:
Código PHP:
Ver original<?php
class geoPlugin {
//the geoPlugin server
var $host = 'http://www.geoplugin.net/php.gp?ip={IP}&base_currency={CURRENCY}';
//the default base currency
var $currency = 'USD';
//initiate the geoPlugin vars
var $ip = null;
var $city = null;
var $region = null;
var $areaCode = null;
var $dmaCode = null;
var $countryCode = null;
var $countryName = null;
var $continentCode = null;
var $latitude = null;
var $longitude = null;
var $currencyCode = null;
var $currencySymbol = null;
var $currencyConverter = null;
function geoPlugin() {
}
function locate($ip = null) {
global $_SERVER;
$ip = $_SERVER['REMOTE_ADDR'];
}
$host = str_replace( '{CURRENCY}', $this->currency, $host );
$response = $this->fetch($host);
//set the geoPlugin vars
$this->ip = $ip;
$this->city = $data['geoplugin_city'];
$this->region = $data['geoplugin_region'];
$this->areaCode = $data['geoplugin_areaCode'];
$this->dmaCode = $data['geoplugin_dmaCode'];
$this->countryCode = $data['geoplugin_countryCode'];
$this->countryName = $data['geoplugin_countryName'];
$this->continentCode = $data['geoplugin_continentCode'];
$this->latitude = $data['geoplugin_latitude'];
$this->longitude = $data['geoplugin_longitude'];
$this->currencyCode = $data['geoplugin_currencyCode'];
$this->currencySymbol = $data['geoplugin_currencySymbol'];
$this->currencyConverter = $data['geoplugin_currencyConverter'];
}
function fetch($host) {
//use cURL to fetch data
curl_setopt($ch, CURLOPT_USERAGENT
, 'geoPlugin PHP Class v1.0');
} else if ( ini_get('allow_url_fopen') ) {
//fall back to fopen()
} else {
trigger_error ('geoPlugin class Error: Cannot retrieve data. Either compile PHP with cURL support or enable allow_url_fopen in php.ini ', E_USER_ERROR); return;
}
return $response;
}
function convert($amount, $float=2, $symbol=true) {
//easily convert amounts to geolocated currency.
if ( !is_numeric($this->currencyConverter) || $this->currencyConverter == 0 ) { trigger_error('geoPlugin class Notice: currencyConverter has no value.', E_USER_NOTICE); return $amount;
}
trigger_error ('geoPlugin class Warning: The amount passed to geoPlugin::convert is not numeric.', E_USER_WARNING); return $amount;
}
if ( $symbol === true ) {
return $this->currencySymbol . round( ($amount * $this->currencyConverter), $float ); } else {
return round( ($amount * $this->currencyConverter), $float ); }
}
function nearby($radius=10, $limit=null) {
trigger_error ('geoPlugin class Warning: Incorrect latitude or longitude values.', E_USER_NOTICE); }
$host = "http://www.geoplugin.net/extras/nearby.gp?lat=" . $this->latitude . "&long=" . $this->longitude . "&radius={$radius}";
$host .= "&limit={$limit}";
}
}
?>
Ahora crear un archivo con el nombre : geoip.php
en el coloca lo siguiente:
Código PHP:
Ver original<?php
require_once('geoplugin.class.php');
$geoplugin = new geoPlugin();
$geoplugin->locate();
$country_code = $geoplugin->countryCode;
switch($country_code) {
case 'RU': //Rusia
header('Location: http://google.ru'); //Aquí es donde los redireccionara. case 'ID': //Indonesia
header('Location: http://google.co.id'); case 'UA': //Ucrania
header('Location: http://google.ua'); }
?>
y por ultimo coloca lo siguiente, en las páginas que quieres que se aplique.