<code><?php
$ip = "8.8.8.8";
$ip_info = json_decode(file_get_contents("http://ip-api.com/json/$ip"), true);
echo "<pre>";
echo print_r($ip_info, true);
echo "
";?>
Вы должны получить вывод как:
Array
(
[as] => AS15169 Google LLC
[city] => Mountain View
[country] => United States
[countryCode] => US
[isp] => Google
[lat] => 37.4229
[lon] => -122.085
[org] => Google
[query] => 8.8.8.8
[region] => CA
[regionName] => California
[status] => success
[timezone] => America/Los_Angeles
[zip] =>
)
Здесь с вашим кодом это будет примерно так:
<code><?php
$ip = $_SERVER['REMOTE_ADDR'];
$ip_info = json_decode(file_get_contents("http://ip-api.com/json/$ip"), true);
$country = $ip_info['country'];
$browser = $_SERVER['HTTP_USER_AGENT'];
$dateTime = date('Y/m/d G:i:s');
$file = "visitors.html";
$file = fopen($file, "a");
$data = "<pre><b>User IP</b>: $ip <b> Browser</b>: $browser <br>on Time : $dateTime <br>from Country : $country
«;fwrite ($ file, $ data);fclose ($ файла);echo "
Hi:)
";?>