How can one get the timezone offset of the physical machine sitting, not the timezone reported by php.ini (and certainly not through geoIP)?
From php.ini or in scripts we can easily set the default timezone. For example, on my box it's
]
In PHP,
if (date_default_timezone_get()) {
echo 'date_default_timezone_set: ' . date_default_timezone_get() . '<br />';
}
if (ini_get('date.timezone')) {
echo 'date.timezone: ' . ini_get('date.timezone');
}
date_default_timezone_set: Asia/Tokyo
date.timezone: Asia/Tokyo
However, the physical server is sitting in Mountain Time with the access logs having the timezone offset string -0700 in them.
Solved: Using exec()
we can get system time and the current timezone offset. This is exactly what was needed. Thanks @codisfy for the inspiration.
echo shell_exec('date +\'%:z\'');
-07:00
Edit: This question (PHP 5.4 Can't Determine Time Zones on its own) is about getting the timezone name, but of importance here is the timezone offset. Thanks for pointing out a possible duplicate, community, alas it is a different requirement.