How to get country from IP address?

Discussion in 'General Programming Chat' started by PhiltheBear, Sep 12, 2008.

  1. PhiltheBear

    PhiltheBear Junior Member

    Joined:
    Feb 17, 2008
    Messages:
    197
    Likes Received:
    93
    This may not be the best place to post this but...

    1) I'm based in the United Kingdom
    2) I have some websites which have affiliate links on them
    3) I get visitors to those sites from many different countries - mainly UK and US but also Canada / Australia....

    Here's the problem - if I get a visitor from the US showing him a UK affiliate link is a waste of time. Therefore, what I want to do is a) check his IP address and b) depending on which country he's from direct him to a webpage which only carries affiliate links valid in his country.

    Oh - I'd prefer to do this without subscribing to some kind of expensive service.

    My programming isn't that great - but I can handle php/html and VB/Javascript at a push.

    Any thoughts?
     
  2. apekillape

    apekillape Senior Member Premium Member

    Joined:
    Dec 13, 2007
    Messages:
    1,077
    Likes Received:
    1,441
    Occupation:
    Basically, I just walk the Earth.
    Location:
    The Layer Cake
    There are geolocation/IP redirect progs in abundance, I've been looking into this at length lately myself. I believe it's usually done in php.

    Code:
    http://ip-to-country.webhosting.info/
    That should help you get started. If I get it up this weekend (pardon the pun) I'll report back.

    N
     
    • Thanks Thanks x 1
  3. BigBlue

    BigBlue Regular Member

    Joined:
    Sep 16, 2008
    Messages:
    479
    Likes Received:
    371
    There's some open source libs in php that can help you do this as well. You can show different geo-targeted ad codes based on the IP detection.

    Here is one such tutorial that explains what you're trying to do exactly.

    hxxp://www.9*99tutori*als.com/tutorial-geo-target-your-visit*ors.html
     
  4. PhiltheBear

    PhiltheBear Junior Member

    Joined:
    Feb 17, 2008
    Messages:
    197
    Likes Received:
    93
    Thank you for your replies - I think I can get what I want out of those sites. I have attempted to give 'thanks' but it may not have worked. If it didn't I'll return and try again later.
     
  5. bhnoobz

    bhnoobz BANNED BANNED

    Joined:
    Jul 26, 2008
    Messages:
    394
    Likes Received:
    107
    Check out
    Code:
    http://www.maxmind.com
    . They have a wide range of IP databases . They also provide code in php/perl/c/c#/c++/python to utilize their databases.
     
  6. PhiltheBear

    PhiltheBear Junior Member

    Joined:
    Feb 17, 2008
    Messages:
    197
    Likes Received:
    93
    Thank you - I'd actually used them before (in a previous life) but forgotten them, largely because the service I'd used was somewhat more complex than the one I need now - and it cost quite a bit!
     
  7. bpaw

    bpaw Junior Member

    Joined:
    Aug 9, 2008
    Messages:
    175
    Likes Received:
    48
    If you have a VPS or dedicated server and are able to install software, MaxMind offers a free option. Just download and install the free GeoIP database and mod_geoip packages. Then use mod_rewrite to redirect traffic based on country to whatever website you want. The last part can simply be done through .htaccess.
     
  8. PhiltheBear

    PhiltheBear Junior Member

    Joined:
    Feb 17, 2008
    Messages:
    197
    Likes Received:
    93
    Unfortunately, their freebie package isn't as accurate as the paid for one. In particular it doesn't deal with countries coming in via users of Yahoo. OTOH I don't know if any of the others do...