Last active
October 13, 2018 13:52
-
-
Save zainaali/3cb0d45a0ae1b479f02d43accc1c42e3 to your computer and use it in GitHub Desktop.
Detect a Visitor's Country by his IP Address PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (!empty($_SERVER['HTTP_CLIENT_IP'])) { | |
$ip = $_SERVER['HTTP_CLIENT_IP'];} | |
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { | |
$ip = $_SERVER['HTTP_X_FORWARDED_FOR']; | |
} else { | |
$ip = $_SERVER['REMOTE_ADDR']; | |
} | |
$url = "http://api.wipmania.com/".$ip; | |
$country = file_get_contents($url); | |
echo $country; | |
The variable $country will store the user’s country in ISO code. http://www.danielpinero.com/downloads/countries.txt here is the full list of countries and their ISO codes. Through your IP address |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment