PDA

View Full Version : language redirecting


Renatus
06-25-2007, 01:00 PM
I'm making a site for different countries in different languages. and i need the visitors to be automatically redirected to the right version of the site. On the moment I have these versions:
1. International, English
2. Great Britain, English
3. United Stated, English
4. Netherlands, Dutch
5. Belgium, Dutch
6. Belgium, French
7. France, French

Here is how visitors should be redirected:
-All visitors from countries 2 till 7 should be redirected to their own country version site.
-All english visitors except US and UK, should be redirected to 1.
-All french visitors except Belgians, should be redirected tot 7.
-All dutch visitors except Belgians, should be redirected to 4.
-All other languages should be redirected to 1.
-All dutch speaking Belgians > 5, french speaking Belgians > 6, rest > 5

I think it would be best to make a blank index.html with the only function to redirect like this. Does anyone know how to do this?

BonRouge
06-26-2007, 11:47 AM
Get an IP-to-country database - just Google for one - and then use php to check where the user is and redirect accordingly.

Renatus
06-26-2007, 05:26 PM
hmmm, I don't know how to do this with php... any tips?...

BonRouge
06-26-2007, 11:21 PM
Sorry, I didn't have all the information at hand...

Go here: http://ip-to-country.webhosting.info/node/view/54

Download the database file and install it.

I use this database for one site. I have a site in Japan (well, I manage the site anyway). The owner of the site wants users who are not in Japan to see an English home page rather than the Japanese one.

Here's the code I use to do that:

<?php
include '../connect.php'; // the database connection
$ip=$_SERVER['REMOTE_ADDR'];
$ip_no = sprintf("%u", ip2long($ip));
$country=mysql_result(mysql_query("SELECT country_code2 FROM iptoc WHERE IP_FROM <= $ip_no and IP_TO >= $ip_no"),0);
if($country!='JP') {
header("Location: http://site.com/eindex.html");
}
else {
header("Location: http://site.com/jindex.html");
}
?>

This is the index page (index.php).

I hope that helps.