-
Get Country and State name from IP Address using GeoIPLocation Library
Kindly follow the below steps.
1. Download PHP GeoIPLocation Library from the link above.
2. Extract geoiploc.php to any folder on your server that is accessible by a web browser.
3. Include the “geoiploc.php file and call getCountryFromIP() function with any IP address.
4. View the sample code below for more details.Download PHP GeoIPLocation Library
Download this: PHP [url=chir.ag/projects/geoiploc/autogen/geoiploc.tar.gz]GeoIPLocation Library[/url] – 230kb (automatically updated daily)
View Code PHP1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
<!--?php include("geoiploc.php"); // Must include this // ip must be of the form "192.168.1.100" // you may load this from a database $ip = $_SERVER["REMOTE_ADDR"]; echo "Your IP Address is: " . $ip . "<br ?-->"; echo "Your Country is: "; // returns country code by default echo getCountryFromIP($ip); echo " \n"; // optionally, you can specify the return type // type can be "code" (default), "abbr", "name" echo "Your Country Code is: "; echo getCountryFromIP($ip, "code"); echo " \n"; // print country abbreviation - case insensitive echo "Your Country Abbreviation is: "; echo getCountryFromIP($ip, "AbBr"); echo " \n"; // full name of country - spaces are trimmed echo "Your Country Name is: "; echo getCountryFromIP($ip, " NamE "); echo " \n"; ?>
Tags: