Website based oin IP address
October 28, 2009 11:37 AM   Subscribe

How do I show different webages to my website visitors based on country of origin?

Currently I read the browser language settings with this code.

This has some disadvantages for my application. How would a code look that shows different websites not based on the language browser settings but on the actual IP location?
posted by yoyo_nyc to Technology (3 answers total) 1 user marked this as a favorite
It's perfectly possible to implement geotargeting based on IP address, but it can result in a (relatively) huuuuge overhead. Unlike when you're checking a browser's own settings, IP address geotargeting requires you to look up the IP address in a database. (Hosted either remotely or locally.)

You can always cheat, and have a landing page where you ask visitors to choose their country. I've noticed a lot of big companies do this, including Ikea and Nike.
posted by ErikaB at 11:48 AM on October 28, 2009

You'd need some sort of IP geolocation package or database to match against.

I'd be careful doing this, however - when working in Germany it was very frustrating being redirected to when my browser preferences told the server I only want English.
posted by sanko at 11:51 AM on October 28, 2009

If you use Apache/Apache2, the module you probably want is called geoip. This may be helpful: GeoIP HOWTO, for Apache2 and Debian.

I agree with others who have pointed out that geolocation is not without downsides. Many big companies eschew geolocation in favor of direct user selection for this reason: it's pretty common for users in one country (or who are using a proxy that makes it look they're in one country) to actually want the content for another. Unless you're doing something evil and want to explicitly prohibit this (like sleazy market-segmentation schemes that block content), you might want to think about just doing that instead. The common method is to show a splashpage or frame on first use of the site, and set a persistent cookie that's used for all other interactions. While it may seem less elegant on first blush, it's often a lot less obnoxious and user-hostile than geolocation.
posted by Kadin2048 at 12:32 PM on October 28, 2009

« Older How to not be a 5 hump chump?   |   Why do large file downloads stall (with no error... Newer »
This thread is closed to new comments.