Files
InternetRadio-Website/api/timezone.php
T
2026-06-17 15:46:26 +02:00

42 lines
834 B
PHP

<?php
header('Content-Type: application/json');
$ip = $_SERVER['REMOTE_ADDR'];
$timezn = geoip_time_zone_by_country_and_region(geoip_country_code_by_name($ip));
if($timezn == "")
{
echo '{"timezone":"11"}';
exit;
}
$time = new DateTime('now', new DateTimeZone($timezn));
$timezoneOffset = $time->format('P');
$DST = $time->format('I');
if (strpos($timezoneOffset , '-') !== FALSE)
{
$str = intval(substr($timezoneOffset, 1, 2));
$arrayval = 11 - $str;
//check DST
if($DST)
$arrayval -= 1;
echo '{"timezone":"' . $arrayval . '"}';
}
else if (strpos($timezoneOffset , '+') !== FALSE)
{
$str = intval(substr($timezoneOffset, 1, 2));
$arrayval = 11 + $str;
//check DST
if($DST)
$arrayval -= 1;
echo '{"timezone":"' . $arrayval . '"}';
}
else
{
echo '{"timezone":"11"}';
}
?>