Por favor, agradecería una ayudita para incorporar este script de Geolocalización.
El script es GRATUITO y el proveedor es que usa webmail/cPanel
Código:
Esta es la respuesta al poner http://j.maxmind.com/app/country.js en el navegador:<script type="text/JavaScript" language="JavaScript" src="http://j.maxmind.com/app/country.js"></script> <script language='JavaScript'>document.write(geoip_country_code());</script>
function geoip_country_code() { return 'ES'; }
function geoip_country_name() { return 'Spain'; }
El CÓDIGO QUE YO HE CREADO es:
Código PHP:
<script type="text/JavaScript" language="JavaScript" src="http://j.maxmind.com/app/country.js"></script>
//GEOIP para seleccionar el idioma.
<?php
/* NOTA: Actualmente a URL recoge el idioma como URL/(page.php if it isn’t the index)?language= '$language'
Y tiene estas inyecciones de código en todas las páginas.
$_vars = new vars;
// define language 'es,en,de,pt,it,fr' todos los posibles valores. Default el primer valor 'es'
$language = $_vars->string('language','es,en,de,fr,it,pt');
El idioma se secciona con botones que añaden a la URL ?language= '$language'
*/
$geo = "<script language='JavaScript'>document.write(geoip_country_code());</script>";
$_vars = new vars;
// define language 'es,en,de,pt,it,fr' todos los posibles valores. Default el primer valor 'es'
$language = $_vars->string('language','es,en,de,fr,it,pt');
$geo = "<script language='JavaScript'>document.write(geoip_country_code());</script>";
if ($geo == ES || $geo == AR || $geo == MX || $geo == VE || $geo == PR || $geo == CL || $geo == UR || $geo == PY || $geo == CO || $geo == BO || $geo == CR || $geo == CU || $geo == DO || $geo == EC || $geo == PA || $geo == PR ){$language = _$vars->'es'}
else if ($geo == GE || $geo == CH || $geo == AS ){$language = _$vars->'de'}
else if ($geo == FR || $geo == BE || $geo == LU ){$language = _$vars->'fr'}
else if ($geo == PT || $geo == BR ){$language = _$vars->'pt'}
else if ($geo == IT ){$language = _$vars->'it'}
else {$language = _$vars->'en'};
?>
Código:
$_vars = new vars; // define language 'es,en,de,pt,it,fr' // default 'es' $language = $_vars->string('language',',es,en,de,fr,it,pt'); // also blank language value must be accepted to define if language was not provided in url // and if so we have to check language with GeoIP and if we get one we should redirect user to that laguage specified url // now im not sure how you get country code with geoip, but i'll help if any problem. // now for ex. if we get country code like this: $geoCode = geoip_country_code(); // now we check if language is set to any available options above, if not we try to define it with geoip and redirect to that desired language version if($language==''){ $countryCodes = array( 'es' => array("ES","AR","MX","VE","PR","CL","UR","PY","CO","BO","CR","CU","DO","EC","PA","PR") 'de' => array("GE","CH","AS"), 'fr' => array("FR","BE","LU"), 'it' => array("PT","BR"), 'pt' => array("IT") ); foreach($countryCodes as $langCode=>$specificCountryCodes){ if(in_array($geoCode,$specificCountryCodes)){ $language = $langCode; break; } } // if we could not define language we set it to english if($language=='') $language = 'en'; header('location:?urlparam1=urlparam2&language='.$language); // urlparam1=urlparam2 this means u have to pass any data got from url if you want or just language param... // why we have to redirect and not just continue? because search engines may overwrite data for example google will display English version bing Spanish depending on the ip. // but if we have language parameter strictly (we dont display data without language parameter, this means user choose language or we do that) in url everything will be ok }
Pero tras sucesivos cambios y pruebas tampoco funciona. Esto es todo lo que yo he sido capaz de hacer. Alguna idea?
Está ahí, casi conseguido. Si lo logramos servirá de referencia para todos.
Muchas gracias.