Skip To Main Content | Home | Sitemap | Contact

How can you check if your PHP script is running under the same time zone set in PHP.INI?

ardor-protection
You probably want your pages to run in your local time zone, not your ISP's time zone which may be different.  If your ISP is located in a different time zone they may have set their time zone in PHP.INI.  You set your own time zone by setting the default time zone in your PHP pages using: date_default_timezone_set('America/Chicago');

This of course is a setting specific to me. I am am in US Central Standard Time zone.

A list of available time zone string constants can be found at: PHP.NET Supported Time zones page.

Script timezone differs from ini-set timezone.
Server timezone in php.ini is = not set.


<?PHP
date_default_timezone_set('America/Chicago');  //US CST

$script_tz = date_default_timezone_get();

if (strcmp($script_tz, ini_get('date.timezone'))) {
    echo "Script timezone differs from ini-set timezone.<br>\n";
    if (ini_get('date.timezone')=="") {
        echo "Server timezone in php.ini is = not set.";
    }else{
        echo "Server timezone in php.ini is = ".ini_get('date.timezone');
    } 
} else {
    echo 'Script timezone and ini-set timezone match.';
}
?>





This Weeks Most Popular Pages Newest Pages
PrintBookmarkComment