Location / Timezone / Currency

Discussion in 'PHP' started by oo7ml, Nov 20, 2011.

  1. #1
    Hi, i need distinguish what content to display on my site depending on where my users are accessing the site from...

    Is there a general php script that is used that has an IP algorithm that can tell / guess what country a user is browsing a site from or di need to develop one from scratch, thanks in advance for your help...
     
    oo7ml, Nov 20, 2011 IP
  2. Anveto

    Anveto Well-Known Member

    Messages:
    697
    Likes Received:
    40
    Best Answers:
    19
    Trophy Points:
    195
    #2
    <?php
     if(isset($_GET["ip"])){
       echo geolocate($_GET["ip"]);
     }
    
     function geolocate($ip){
       $raw_html = file_get_contents("http://www.geody.com/geoip.php?ip=$ip");
       if(preg_match('/Location:(.*)/',$raw_html,$matches)){
         $location_raw = $matches[1];
    
         //Get rid of pesky HTML tags
         $location = preg_replace("/<[^>]*>/","",$location_raw);
         return $location;
       }else{
         return "ERROR";
       }
     }
    ?>
    PHP:
    Then I would make a script that matches the country and finds a currency based off of the result of the above script

    Source: http://stackoverflow.com/questions/...cation-without-having-the-user-install-google

    Google usually has decent answers :D
     
    Anveto, Nov 23, 2011 IP
  3. oo7ml

    oo7ml Well-Known Member

    Messages:
    656
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    105
    #3
    Cool, thanks for your help
     
    oo7ml, Nov 23, 2011 IP