Help - Search - Members - Calendar
Full Version: Which country
The Planet Forums > General > The Lounge
lindem
Hi Folks!

Does anybody know how I can create a page that redirect the visitor to his language page?

Example: If someone from USA enters into my site he goes to www.mysite.com/english / if someone from japan enters into my site he goes to www.mysite.com/japan .. and so on

How could I do this?

Regards!
Catalyst
Google...

http://www.linuxjournal.com/article/7856
lindem
thanks a looooooooooooooooot!! icon_wink.gif
Catalyst
The server they talk about in the article (like most Geolocation servers) can be seriously wrong. But, if you're a PHP coder, you should be able to use the example to figure out what to change.

Also, using curl() instead of fopen() is more beneficial, since fopen() should be disabled.

For that matter, you could say...
CODE
$x_hostname=gethostbyaddr($_SERVER['REMOTE_ADDR']);

if (substr($x_hostname, -3, 3)==".jp")

 header("Location: /japan/");
Sure, it's not gonna get everyone... but it's a quick-and-dirty way.

Another would probably be to take adantage of pear-Net_DNSBL, and check the $_SERVER['REMOTE_ADDR'] against japan.blockholes.us --- those zones are updated more frequently.
lindem
Let's see if it is working guys...

If you are from Brazil you should be redirect to /br if not you should go to /site

Tell me if it is working because I can't access from another country =)

http://www.trixhost.com

Thanks all
dreamwiz
Im not from brazil but the site opens up icon_smile.gif If your the webmaster of this website you would like to change "sing-up" in the upper rightcorner to sign-up or Sign Up or something icon_razz.gif
GraphicsGuy
QUOTE (lindem)
Hi Folks!

Does anybody know how I can create a page that redirect the visitor to his language page?


If language is the issue and not necessarily country location, then a simple javascript redirect in the page header would work. For example the one below from JavaScript Kit. This way the users browser language determines the language version of the site to send them to.


Configuration instructions are included in comments within script.

CODE
<script>
/*
Browser Language Redirect script- By JavaScript Kit
For this and over 400+ free scripts, visit [url="http://www.javascriptkit.com/"]http://www.javascriptkit.com[/url]
This notice must stay intact
*/
//Enter ISO 639-2 letter Language codes to detect (see: [url="http://www.w3.org/WAI/ER/IG/ert/iso639.htm"]http://www.w3.org/WAI/ER/IG/ert/iso639.htm[/url]):
var langcodes=new Array("en", "fr", "es", "ja", "zh", "default")
//Enter corresponding redirect URLs (last one is for default URL):
var langredirects=new Array("index.htm", "french.htm", "spanish.htm", "japan.htm", "chinese.htm", "index.htm")
var languageinfo=navigator.language? navigator.language : navigator.userLanguage
var gotodefault=1
function redirectpage(dest){
if (window.location.replace)
window.location.replace(dest)
else
window.location=dest
}
for (i=0;i<langcodes.length-1;i++){
if (languageinfo.substr(0,2)==langcodes[i]){
redirectpage(langredirects[i])
gotodefault=0
break
}
}
if (gotodefault)
redirectpage(langredirects[langcodes.length-1])

</script>
EvolutionCrazy
i use this php code to detect the language used (not geografic related)

CODE
//lingue supportate

$lang_supported[] = "it";

$lang_supported[] = "en";

$lang_supported[] = "us";

$lang_supported[] = "de";



//lingua di default

$lang_default = "it";



//controllo lingua solo se l'utente non ha già settata una prima

if(!isset($lang)){

    $lang = $_SERVER['HTTP_ACCEPT_LANGUAGE'];

    $lang = explode(",",$lang);

    $lang1 = explode("-",$lang['0']);

    $lang1 = strtolower("".$lang1['0']);

    $lang2 = explode("-",$lang['1']);

    $lang2 = strtolower("".$lang2['0']);

    if(in_array($lang1, $lang_supported))

 $lang = $lang1;

    elseif(in_array($lang2, $lang_supported))

 $lang = $lang2;

    else

 $lang = $lang_default;

}

//fine controllo lingua


at that point you will have the var

$lang that content the value of the language setted in the browser (mozilla does it dunno the others icon_razz.gif)
boxrec
www.maxmind.com

I use it and it's simple, cheap + effective
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.