Is it be possible to geo-target my product pages with php?

Discussion in 'PHP' started by Altug, Nov 5, 2010.

  1. #1
    Hi guys,

    I'm a bit of a PHP noob so I'm sorry if this is a silly question.

    I was just wondering, I have a site that I have an affiliate store on..The product pages are php. Now most of my users are from the U.S (70%) but I do have users from the U.K too.

    I was wondering if there was a code or script I could get that would Geo-Target my page depending on who landed on it?

    Basically it would be as simple as "show code 1 if the visitor is from the U.S (or rest of the world)" and "show code 2 if the visitor is from the U.K"

    Or would it be possible to have a script like this made? I imagine it would be pretty simple? What do you guys think.

    Possible or not?

    Thanks a lot :)
     
    Altug, Nov 5, 2010 IP
  2. Nythe

    Nythe Peon

    Messages:
    30
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I don't think there is any built-in function as such to gather information based on IP in PHP. However, there are web service apis which will allow you to do this for free. For instance, the following code will return the country:

    <?php

    $country = '';
    $IP = $_SERVER['REMOTE_ADDR'];

    if (!empty($IP)) {
    $country = file_get_contents('http://api.hostip.info/country.php?ip='.$IP);
    }
    ?>

    Excerpted from: http://www.daniweb.com/forums/thread77998.html
     
    Nythe, Nov 5, 2010 IP
    Altug likes this.
  3. bencummins

    bencummins Peon

    Messages:
    55
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Try this:
    http://www.maxmind.com/app/ip-location

    There are apache modules which you can get, and when its all set up, you can easily use php to pull out the relevant information.

    They even do a free lite version which should probably be enough!
     
    bencummins, Nov 5, 2010 IP
    Altug likes this.
  4. Altug

    Altug Active Member

    Messages:
    188
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    53
    #4
    Thanks for your help guys :) I will check them out

    Thats really helpful

    Altug
     
    Altug, Nov 6, 2010 IP