Dealing with PHP 5.3 Timezone Errors: Difference between revisions

From Acenet Knowledgebase
Jump to navigation Jump to search
No edit summary
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
PHP 5.3 requires that you set the timezone setting within PHP, and not use the system timezone settings.  The error may look similar to the following:
PHP 5.3 requires that the timezone setting be set within PHP, and will not use the system timezone settings.  The warning that occurs may look similar to the following:


<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
Line 6: Line 6:
</syntaxhighlight>
</syntaxhighlight>


There are two ways to handle this.  Either edit the local php.ini file, or edit your index.php file.
The way to handle this warning is to set the timezone setting in PHP.  There are two ways to go about this.  Either edit the local php.ini file, or edit the index.php file.


====Edit your local php.ini file====
====Edit your local php.ini file====


Locate your local php.ini file, and add the following line to it:
Locate the local php.ini file, and add the following line to it:


<syntaxhighlight lang="bash">date.timezone = "America/Detroit"</syntaxhighlight>
<syntaxhighlight lang="bash">date.timezone = "America/Detroit"</syntaxhighlight>
Line 20: Line 20:
====Edit your index.php file====
====Edit your index.php file====


Add the following line to your index.php file, just under the php tag near the top of the file:
Add the following line to the index.php file, just under the php tag near the top of the file:


<syntaxhighlight lang="bash">date_default_timezone_set('America/Detroit'); </syntaxhighlight>
<syntaxhighlight lang="bash">date_default_timezone_set('America/Detroit'); </syntaxhighlight>
Line 26: Line 26:
====Locating your local TimeZone name====
====Locating your local TimeZone name====


You can find the official name of your timezone by visiting the PHP website:
The official name of the local timezone can be found by visiting the following PHP website:


[http://www.php.net/manual/en/timezones.php Timezones at php.net]
[http://www.php.net/manual/en/timezones.php Timezones at php.net]

Latest revision as of 11:39, 13 January 2013

PHP 5.3 requires that the timezone setting be set within PHP, and will not use the system timezone settings. The warning that occurs may look similar to the following:

<syntaxhighlight lang="bash"> Warning: strftime() [function.strftime]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. </syntaxhighlight>

The way to handle this warning is to set the timezone setting in PHP. There are two ways to go about this. Either edit the local php.ini file, or edit the index.php file.

Edit your local php.ini file

Locate the local php.ini file, and add the following line to it:

<syntaxhighlight lang="bash">date.timezone = "America/Detroit"</syntaxhighlight>

More details on custom php.ini files can be found here:

How can I change PHP settings?

Edit your index.php file

Add the following line to the index.php file, just under the php tag near the top of the file:

<syntaxhighlight lang="bash">date_default_timezone_set('America/Detroit'); </syntaxhighlight>

Locating your local TimeZone name

The official name of the local timezone can be found by visiting the following PHP website:

Timezones at php.net