<?php

date_default_timezone_set('UTC');

$ip = $_SERVER['REMOTE_ADDR'];
$date = date("Y-m-d H:i:s");

// Geolocation
$json = @file_get_contents("http://ip-api.com/json/$ip");
$data = json_decode($json);

$country = $data->country ?? 'Unknown';
$city    = $data->city ?? 'Unknown';

$line =
"====================================\n" .
"IP      : $ip\n" .
"Country : $country\n" .
"City    : $city\n" .
"Date    : $date\n" .
"====================================\n\n";

file_put_contents("visitor.txt", $line, FILE_APPEND);

?>