<?php

// Set the response content type to JSON
header('Content-Type: application/json');

// Get the client's IP address
$clientIp = $_SERVER['REMOTE_ADDR'];

// Get the client's location using the GeoIP extension
$record = geoip_record_by_name($clientIp);

// Get the client's timezone based on their country code
$timezone = timezone_name_from_abbr('', $record['country_code']);

// If the timezone is not found, default to UTC
if (!$timezone) {
    $timezone = 'UTC';
}

// Get the current date and time in the desired format
$now = new DateTime('now', new DateTimeZone($timezone));
$nowString = $now->format('Y-m-d\TH:i');

// Create an associative array with the date and time
$response = array(
    'date' => $nowString,
);

// Return the response as JSON
echo json_encode($response);
