Reputation: 13
I'm not able to run this PHP code. According to phptester.net.
file_get_contents() has been disabled for security reasons on line number 2
Is there any way to skip it? yesterday it worked, I have no idea why now doesn't work.
$ip = $_SERVER['REMOTE_ADDR'];
$details = json_decode(file_get_contents("http://ipinfo.io/{$ip}"));
echo $details;
Thank you.
Upvotes: 0
Views: 3355
Reputation: 1571
According to ipinfo.io, if you want only country code then you can pass it to url...
$ip = $_SERVER['REMOTE_ADDR'];
$details = file_get_contents("http://ipinfo.io/{$ip}/country");
echo $details;
Output
IN
Or your IP country code.
Test code here
Read ipinfo.io documents here
Upvotes: 1
Reputation: 74217
Get rid of json_decode()
. The string that you're trying to pass expects it to be JSON and the argument won't be understood; it just needs the IP address.
You can then grab the JSON output from there, if that is what you're really after.
Upvotes: 2