views:

47

answers:

4

Hii,

We want to redirect our users to one of our web pages corresponding to the users city (location based upon the users ip address and using some ip location databases)

My question is, how to make it work fast? for example in website gropoun, whenever the user visits, it instantly takes the user to its city page.

Thanks.

Edit: We are using PHP

+1  A: 

You should determine user ip from httpRequest afterwards use some kind of database for example geoip

aauser
+2  A: 

Do you want to do this server or client side? If client side (ie, using javascript), you can use one of many geoip services out there. One in particular is Yahoo!'s YGL

Also, you can do it server-side using pretty much and language or framework. You could make API or service calls to third party geoip providers, or you can load the data into your database and do your own look up.

You will also need to "default" to a region or zipcode as every IP address can not be determined. For example, one web application that I currently work on has a 95% USA audience, so we default to the geographical center of the country which is 66952.

Kris Krause
Nice work Kris, expanding on your answer, using server side is possibly faster as it means you can direct the user straight away. Rather than having to wait for the client side to load and then redirect. However, I think your more likely to find free client side versions than server side.
Alex Key
+1  A: 

Cache, cache, cache everything. Cache lookups in your IP table, cache the results for individual users in their session or cookies, cache the rendered localization information portion of your pages (or at least the query intensive parts.)

There are more details that could be given, but it all depends on what your bottlenecks are. (After all there's no point in implementing complex caching on the routing side of things if the bottleneck is in rendering localized information because your DB calls take almost half a second to run). I cannot tell you where the bottlenecks in your application are / will be. You'll need to profile it first -- then optimize on the basis of what the profiler tells you.

Sean Vieira
+1  A: 

I have done this for a few clients server-side using the lookup service http://ipinfodb.com/ip_location_api.php.

Just remember to store IP addresses and locations in the database so you do not do redundant lookups. I used the time zone data to determine the visitor's region.

Roxtonic