1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Finding out a visitors country of origin ??

Discussion in 'PHP' started by jdavidson, Jul 4, 2008.

  1. #1
    I'm not even sure if this is possible, or easy to do.

    BUT...

    Im wanting to display some info on my site which will change depending on where the visitor comes from.

    E.G.

    if ($country = USA){
    echo "You are from USA";
    }

    elseif($country = China){
    echo "Something in Chinese";
    }


    I want to get the 'country' variable from the browser. Lots of programs do this, for example, AWSTATS can tell you how many visitors have came from USA, UK, China etc...But I have no idea how they pull in this information?
    From the visitors IP?

    Any advice/help would be great.
    Thanks guys.
     
    jdavidson, Jul 4, 2008 IP
  2. zyklon

    zyklon Active Member

    Messages:
    274
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    55
    #2
    here is a function u can use if you have the ip:

    function getLocationCaidaNetGeo($ip)
     {
     $NetGeoURL = "http://netgeo.caida.org/perl/netgeo.cgi?target=".$ip;
      
     if($NetGeoFP = fopen($NetGeoURL,r))
     {
             ob_start();
    
             fpassthru($NetGeoFP);
             $NetGeoHTML = ob_get_contents();
             ob_end_clean();
    
     fclose($NetGeoFP);
     }
     $location = array();
     $location = preg_match ("/COUNTRY:(.*)/i", $NetGeoHTML, $temp) or die("Could not find element COUNTRY");
    
    
     return $location;
     }
    PHP:
     
    zyklon, Jul 4, 2008 IP
  3. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #3
    or try hostip.info
     
    EricBruggema, Jul 4, 2008 IP
  4. Stryder

    Stryder Guest

    Messages:
    124
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #4
    This returns inaccurate results.

    Here's a note from this site:

     
    Stryder, Jul 5, 2008 IP
  5. jdavidson

    jdavidson Peon

    Messages:
    216
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks guys, for your help.

    I was going to test the above php function out today, but not much point if its completely wrong .. "wildly incorrect results"

    Im gonna try out hostip.info > thanks to "EricBruggema"
     
    jdavidson, Jul 5, 2008 IP
  6. gezzle

    gezzle Peon

    Messages:
    108
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    gezzle, Jul 5, 2008 IP
  7. Vooler

    Vooler Well-Known Member

    Messages:
    1,146
    Likes Received:
    64
    Best Answers:
    4
    Trophy Points:
    150
    #7
    Why Rely on ThirdParty Sites? :) Why not have our own script to do this, and yes we have one now for DP members.

    Here is script I wrote a while ago
    http://forums.digitalpoint.com/showthread.php?t=918336

    No dependencies, No external linkage, No Server Load.

    I hope it helps.

    regards
     
    Vooler, Jul 5, 2008 IP
  8. shels

    shels Peon

    Messages:
    25
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Maxmind I think is the best one. But bit difficult to configure.
     
    shels, Jul 6, 2008 IP
  9. Vooler

    Vooler Well-Known Member

    Messages:
    1,146
    Likes Received:
    64
    Best Answers:
    4
    Trophy Points:
    150
    #9
    "Maxmind"? respected member shels, are you addressing to author of topic or me? Becuase I cant see user entitled "Maxmind".

    Well shels,

    The script I provided free, installs in few clicks without anymess, and does this job perfectly.
    A code for doing job that author of topic request will be something like:

    I hope it helps.

    regards
     
    Vooler, Jul 6, 2008 IP
  10. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #10
    Maxmind update their database regularly. We never had an issue with maxmind.
     
    mwasif, Jul 6, 2008 IP