Jump to content
  • Advertisement
Sign in to follow this  
streamer

[web] Visitor by country in PHP

This topic is 3895 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all! Recently I made one web page that is made in four languages. I would like to make that if visitor is coming from Germany, web page is displayed in German language. How can I determine which visitor came from which country? Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
You would need an IP to Country database listing. You could pull the users IP from the $_SERVER variable in PHP, then look up where their from in the database. I can't say I've ever done this, but it should work in theory.

Share this post


Link to post
Share on other sites
Hm. Ok. I understand that, but I need just ip range for 3-4 countries. Is there some web page from which I can get that info?

Share this post


Link to post
Share on other sites
Quote:
Original post by Sander
At software77.net. It was the first hit on "Free IP-to-country database". They're really useful you know, these search engine thingamajingies :-)


I googled before I had post. I found few databases also but they were awfully big. I need just ip-s from 4 countries :D not database of few megabyte.
Anyway thanks, this looks very good.

Share this post


Link to post
Share on other sites
Quote:
Original post by streamer
Quote:
Original post by Sander
At software77.net. It was the first hit on "Free IP-to-country database". They're really useful you know, these search engine thingamajingies :-)


I googled before I had post. I found few databases also but they were awfully big. I need just ip-s from 4 countries :D not database of few megabyte.
Anyway thanks, this looks very good.

Of course you can always delete the records of the countries you're not interested in. But unless you're really running out of disk space, I wouldn't bother. Having an index on the IP column which datatype is probably an simple unsigned integer, querying should be really fast.
Alternatively you can attempt to detect the browser language, which doesn't say anything about the request origin but may be sufficient for selecting a default language.

Share this post


Link to post
Share on other sites
Quote:
Original post by streamer
Recently I made one web page that is made in four languages. I would like to make that if visitor is coming from Germany, web page is displayed in German language. How can I determine which visitor came from which country?


Don't. This would mean deciding what languages your visitors want to read, which is extremely annoying. Let your visitors decide for themselves: $_SERVER['HTTP_ACCEPT_LANGUAGE']. If a visitor from Germany doesn't have 'de' set as his primary accepted language, it's very likely that he either has other language preferences (which you should respect, instead of defaulting to German), or doesn't want to be traced as being from Germany for privacy reasons (and it would be rude to trace him nonetheless).

Share this post


Link to post
Share on other sites
Quote:
Original post by ToohrVyk
Quote:
Original post by streamer
Recently I made one web page that is made in four languages. I would like to make that if visitor is coming from Germany, web page is displayed in German language. How can I determine which visitor came from which country?


Don't. This would mean deciding what languages your visitors want to read, which is extremely annoying. Let your visitors decide for themselves: $_SERVER['HTTP_ACCEPT_LANGUAGE']. If a visitor from Germany doesn't have 'de' set as his primary accepted language, it's very likely that he either has other language preferences (which you should respect, instead of defaulting to German), or doesn't want to be traced as being from Germany for privacy reasons (and it would be rude to trace him nonetheless).


This looks good. Even better than IP lookup. I don't mean to be rude and not respecting peoples privacy. Just, for example, there are lot of people that doesn't speak any foreign language, and I would like to give them a fast start, representing web page in their native (or preferred sounds much better) language.

Share this post


Link to post
Share on other sites
Quote:
Original post by ToohrVyk
Quote:
Original post by streamer
Recently I made one web page that is made in four languages. I would like to make that if visitor is coming from Germany, web page is displayed in German language. How can I determine which visitor came from which country?


Don't. This would mean deciding what languages your visitors want to read, which is extremely annoying. Let your visitors decide for themselves: $_SERVER['HTTP_ACCEPT_LANGUAGE']. If a visitor from Germany doesn't have 'de' set as his primary accepted language, it's very likely that he either has other language preferences (which you should respect, instead of defaulting to German), or doesn't want to be traced as being from Germany for privacy reasons (and it would be rude to trace him nonetheless).

Awesome!

IE seems to follow the Windows regional settings, but I can't seem to find any place to change it in Firefox?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!