Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Aug 2008
    Posts
    61
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Geo targetting page of my site

    Well actually just a few links, I would like people only in one country to see these links, not the rest of the world - what is the bes way of doing this?

    Regards

  • #2
    The Apostate Apostropartheid's Avatar
    Join Date
    Oct 2007
    Posts
    3,215
    Thanks
    16
    Thanked 265 Times in 263 Posts
    Is there any reason for this? You can really, really annoy people by doing that kind of thing (I'm looking at you, Hulu.)

  • #3
    New Coder
    Join Date
    Aug 2008
    Posts
    61
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Yes, the links take the user to a shop where we sell products only allowed to be sold in our home country

  • #4
    The Apostate Apostropartheid's Avatar
    Join Date
    Oct 2007
    Posts
    3,215
    Thanks
    16
    Thanked 265 Times in 263 Posts
    A quick google found this DB

  • #5
    Senior Coder
    Join Date
    Jan 2005
    Location
    Memphis, TN
    Posts
    1,798
    Thanks
    8
    Thanked 131 Times in 129 Posts
    using PHP this will work. Maybe not 100% fool proof but it's worth a shot.

    PHP Code:
    <?php
    $Users_IP_address 
    $_SERVER["REMOTE_ADDR"];

    function 
    countryFromIP($ipAddr)
    {
       
    //Originally developed by Roshan Bhattarai http://roshanbh.com.np
       //Modified by Alan Jackson http://tugbucket.net

      
    ip2long($ipAddr)== -|| ip2long($ipAddr) === false trigger_error("Invalid IP"E_USER_ERROR) : "";
      
    $xml file_get_contents("http://api.hostip.info/?ip=".$ipAddr);
      
    preg_match("@<countryAbbrev>(.*?)</countryAbbrev>@si",$xml,$cc_match);
      
    $ipDetail=$ipDetail['country_code']=$cc_match[1];
      return 
    $ipDetail;

      
    $IPDetail=countryFromIP($Users_IP_address); 

    $countryCode = array("UK""GB"); // slap in your country codes in theis array 

    if (in_array($IPDetail['country_code'], $countryCode)) {
      echo 
    "UK based links here.";
    }
    else {
      echo 
    "Non UK based links here.";
    }
    ?>
    Stop making things so hard on yourself.
    i is tugbucket :: help raise tugburg :: Whitehaven Kiwanis

  • #6
    The Apostate Apostropartheid's Avatar
    Join Date
    Oct 2007
    Posts
    3,215
    Thanks
    16
    Thanked 265 Times in 263 Posts
    Also, make sure you allow a manual override in case it screws up.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •