1

I am creating a news website like nytime.com but multicountries ( different news and languages for different countries ).

So I need to convert IP address to country and so redirect user to the appropriate subdomain. For example, if a spanish user go to mysite.com he will be redirected to es.mysite.com.

You can propose me other solutions if you want but remember it must be optimized for search engines.

xRobot
  • 25,579
  • 69
  • 184
  • 304
  • 1
    Personally I hate it when I get a different site based on the country I am in (Google...), so I just use language detection using $_SERVER["HTTP_ACCEPT_LANGUAGE"] and just change the language settings and don't serve different content. – jeroen Jul 09 '12 at 18:13
  • This isn't only a language issue but also a content issue ( different content for different country ). So an italian user in the USA, will see first USA news ( and then he can change country's news later ). – xRobot Jul 09 '12 at 18:18
  • I know, that's why I just put in a comment... – jeroen Jul 09 '12 at 20:39

6 Answers6

1

You can't directly convert IP to country. You can however use a database that has IPs/IP ranges against countries which is how most sites do it.

imperium2335
  • 23,402
  • 38
  • 111
  • 190
1

MaxMind sell this data in a format suitable for many databases and programming languages, or as an Apache plugin. It's not always correct, but it's probably as accurate as you can get.

http://www.maxmind.com/app/ip-location

The advantage of this rather than a JS approach is that the user is not prompted to disclose their location.

Purpletoucan
  • 6,472
  • 2
  • 21
  • 28
0

http://html5demos.com/geo/

This is a good free solution.

You can pay for php geolocationing, but it is expensive.

Max Hudson
  • 9,961
  • 14
  • 57
  • 107
0

http://software77.net/geo-ip/

in the sidebar on the right you can download the databases

there are similar databases and services, just google "ip to country"

Florian Brinker
  • 735
  • 7
  • 17
0

Check out

Basically you need a database where you can compare the IP in hand and find out its country. Maxmind provides you a self-hosted database & code samples, whereas IPinfoDB gives out the free API service.

DavChana
  • 1,944
  • 17
  • 34
0

There is no inbuilt method to that. There are web-services on the internet that will provide such mapping. Such databases "GeoIP databases" are also available for local use.

But it would be best to subscribe to an updated web-service and use that to get the location. Google's Client Location API's should help you here.

Some modern browsers will send you the users location. You can use that. But since this is not followed by all browsers, it is not reliable. You can check out the Geo Location API provided by w3.org.

nunespascal
  • 17,584
  • 2
  • 43
  • 46