phpmady Posted March 18, 2010 Share Posted March 18, 2010 Hi, I have a project where i want to display a visitor status, number of peoples watching in what country, is there any ready code for that, pls help me, or else give me idea to make it. Thanks In advance Cheers Quote Link to comment Share on other sites More sharing options...
teamatomic Posted March 18, 2010 Share Posted March 18, 2010 http://www.maxmind.com/app/geoip_country HTH Teamatomic Quote Link to comment Share on other sites More sharing options...
phpmady Posted March 20, 2010 Author Share Posted March 20, 2010 hi, I coulnt find anything under the link, please help me Quote Link to comment Share on other sites More sharing options...
Ruzzas Posted March 20, 2010 Share Posted March 20, 2010 GeoIP is a complicated code to use. <?php /** * GeoIP Country Database Example * * @version $Id$ * @package geoip * @copyright © 2006 Lampix.net * @author Dragan Dinic <dinke@lampix.net> */ require_once("geoip.inc"); $gi = geoip_open("GeoIP.dat", GEOIP_STANDARD); $ip = $_SERVER['REMOTE_ADDR']; //if you test on localhost use IP bellow for test //since $_SERVER['REMOTE_ADDR'] would be 127.0.0.1 //$ip = "89.216.226.174"; $country_name = geoip_country_name_by_addr($gi, $ip); $country_code = geoip_country_code_by_addr($gi, $ip); if($country_name) { echo "Your country is: $country_name <br />"; echo "Country Code is: $country_code <br />"; } else { echo "Sorry, we weren't able to locate you."; } geoip_close($gi); ?> http://geolite.maxmind.com/download/geoip/api/php/geoip.inc save that and download this http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz Place them in the same folder as the script. Quote Link to comment Share on other sites More sharing options...
phpmady Posted March 20, 2010 Author Share Posted March 20, 2010 GeoIP is a complicated code to use. <?php /** * GeoIP Country Database Example * * @version $Id$ * @package geoip * @copyright © 2006 Lampix.net * @author Dragan Dinic <dinke@lampix.net> */ require_once("geoip.inc"); $gi = geoip_open("GeoIP.dat", GEOIP_STANDARD); $ip = $_SERVER['REMOTE_ADDR']; //if you test on localhost use IP bellow for test //since $_SERVER['REMOTE_ADDR'] would be 127.0.0.1 //$ip = "89.216.226.174"; $country_name = geoip_country_name_by_addr($gi, $ip); $country_code = geoip_country_code_by_addr($gi, $ip); if($country_name) { echo "Your country is: $country_name <br />"; echo "Country Code is: $country_code <br />"; } else { echo "Sorry, we weren't able to locate you."; } geoip_close($gi); ?> http://geolite.maxmind.com/download/geoip/api/php/geoip.inc save that and download this http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz Place them in the same folder as the script. Hi, Thank you for your code, but what i need is, displaying all the users ipaddress and country flag who are viewing my website online. Thank You Quote Link to comment Share on other sites More sharing options...
phpmady Posted March 20, 2010 Author Share Posted March 20, 2010 Hi, Visitors Country code with flag, hope i ll get the solution Quote Link to comment Share on other sites More sharing options...
teamatomic Posted March 20, 2010 Share Posted March 20, 2010 When you use the api code and query the dat file with an IP you will be returned a country code. Something like us,ca,uk. Take the country code and: echo"$country_code <img src=\"./flags/$country_code.png\" border=0>"; HTH Teamatomic Quote Link to comment Share on other sites More sharing options...
teamatomic Posted March 21, 2010 Share Posted March 21, 2010 Hi, had posted a solution to help those who wanted country based flags displayed on their site. Unfortunately they were myopically removed. But here is how to do it. make a folder on your website named "geoip" then go the the site where the free geoip is located. Download the dat file http://www.maxmind.com/app/geolitecountry under link named "Download the latest GeoLite Country Binary Format" uncompress it and save it to the geoip folder. Then go here http://geolite.maxmind.com/download/geoip/api/php/ and save all the .hph and .inc files to the geoip folder. Here is a function that I wrote that is a bit easier to use and includes a flag img tag. <?php //function usage // function(1,2,3) //1 is the ip address //2 is the method - short|long //short = US //long=Unites States //3 is the image will we return it or not //image = yes|no // RETURN //the function return an array, //array[0] is the textual representation of the country //array[1] is the image tag //$array=get_flag($ip,short,yes); //sample vars for function //$ip='24.24.24.24'; //$method_type='short'; //$image_use='yes'; // function get_geoip($ip,$method_type,$image_use) { $array=array(); include("./geoip.inc"); $gi = geoip_open("./GeoIP.dat",GEOIP_STANDARD); $country_code = geoip_country_code_by_addr($gi, "$ip"); $country_name = geoip_country_name_by_addr($gi, "$ip"); geoip_close($gi); $cc=strtolower($country_code); $img_str = "<img src=\"./flags/$cc.png\" border=0>"; //geoip_close($gi); if($method_type == 'short')$array[0]=$country_code; if($method_type == 'long')$array[0]=$country_name; if($image_use == 'yes')$array[1]=$img_str; return $array; } $ip='24.24.24.24'; $returned_array=get_geoip($ip,'long','yes'); print_r($returned_array); ?> If you have any questions just ask. HTH Teamatomic Quote Link to comment Share on other sites More sharing options...
phpmady Posted March 21, 2010 Author Share Posted March 21, 2010 Thank You for your post teamtonic, its so nice to go step by step, where can i download the flags one more thing, i am happy what i have done, whethet it will show Users Online :: STATUS No ipaddress country flag 1 27.23.25.9 france france flag 2 27.23.25.91 italy italy flag 3 27.23.25.92 nepal nepal flag can i get like this result... Thank You Quote Link to comment Share on other sites More sharing options...
teamatomic Posted March 21, 2010 Share Posted March 21, 2010 Hi, flags are all over the place but good ones can be a bit harder to find. I'll attach the ones I use. HTH Teamatomic [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
phpmady Posted March 21, 2010 Author Share Posted March 21, 2010 Hi, flags are all over the place but good ones can be a bit harder to find. I'll attach the ones I use. HTH Teamatomic Thank You, Hi thank you very much, your help is really appreciated, i found the solution Thanks a Lot Quote Link to comment Share on other sites More sharing options...
phpmady Posted March 23, 2010 Author Share Posted March 23, 2010 Hi, flags are all over the place but good ones can be a bit harder to find. I'll attach the ones I use. HTH Teamatomic Hi, I like to have list of visitors online with their country flags, is it possible, where i have attached my result and one i need, Pls go through the atachment, and you will find it what i need. [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.