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.
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:
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 have a look at Maxming GeoLite Country to get started. http://www.maxmind.com/app/geoip_country I made a sample here : http://get-my-ip.info/
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
"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