Redirect to page according to user's language

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Sindarin
Forum Regular
Posts: 521
Joined: Tue Sep 25, 2007 8:36 am
Location: Greece

Redirect to page according to user's language

Post by Sindarin »

I have two versions of a site (one in English and one in Greek). How can I check if the user's language is Greek and send him to the Greek site instead of the English one?
robble
Forum Newbie
Posts: 11
Joined: Fri Aug 24, 2007 6:34 am

Re: Redirect to page according to user's language

Post by robble »

To be honest I'm not sure theres a completely accurate way. Most (large) international websites display an option of languages to choose from and I guess save this info in a cookie or something similar so the user is not prompted again.

You could find the country of a user (closest thing I guess to finding the language) by using their ip address and checking it against a database. There's a few classes out there which will do it for you.

You could try this one (I haven't used it before though..)

http://www.phpclasses.org/browse/package/2363.html
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Redirect to page according to user's language

Post by Christopher »

You may need to do several checks. Take a look at the browser variable in $_SERVER["HTTP_ACCEPT_LANGUAGE"].
(#10850)
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Re: Redirect to page according to user's language

Post by Kieran Huggins »

arborint++

But always provide the option to switch.
Post Reply