Created
January 28, 2016 16:14
-
-
Save fuckuppro/87a3e6a8ca06a74d2a57 to your computer and use it in GitHub Desktop.
best geo ip freegeoip.net/json/192.168.1.1
This file contains 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
<? | |
$ip = '192.168.11.5'; | |
if($ch = curl_init()){ | |
$url = "http://freegeoip.net/json/". $ip; | |
$headers = array( | |
"Content-type: application/json", | |
"Accept: application/json", | |
"Accept-Language:ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4" | |
); | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL,$url); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_TIMEOUT, 30); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); | |
$data = curl_exec($ch); | |
if (curl_errno($ch)) { | |
// curl_error($ch); | |
} else { | |
$arData = json_decode($data, true) ; | |
} | |
curl_close($ch); | |
} | |
print_r($arData); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment