5

I keep getting this error:

Message: date() [function.date]: 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. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/New_York' for 'EST/-5.0/no DST' instead

I have edited my php.ini and added this to the end of it: date.timezone = "America/New_York"

After saving the php.ini and restarting Apache, I still get the error. I have also tried rebooting the entire server to no avail.

I'm running cPanel/WHM on CentOS 5.6 if that makes any difference. Also, the PHP handler is suphp.

I'm not sure what to try next... any guidance?

JT White
  • 185
  • 1
  • 1
  • 6
  • 1
    On my setup, I have many `php.ini` (apache, cli, php-fpm, etc…) did you edit the right one? – greut Jan 14 '12 at 10:19
  • Its not an error its a message so everything will work fine but php is informing you that its not good idea to rely on system timezone setting .. thats all ... but its strange that after you changed setting the message is still there :/ – B14D3 Jan 14 '12 at 11:26
  • Presuming you have the right php.ini file, 3 observations (although all may be irrelevant): a) There should already be an entry for `date.timezone` in your php.ini file (i.e. your new entry might not take precedence) b) There is a specific `[Date]` section in php.ini - which is not at the bottom of the file, entries outside of that might not be processed as expected; c) The timezone doesn't need to be quoted - again, I am uncertain of the effect. Try `php -i | grep timezone` and see what you get. – cyberx86 Jan 16 '12 at 17:17

4 Answers4

2

open the appropriate php.ini file and add the following, replacing the time zone with the one which is correct for you (list of timezone names - http://php.net/date.timezone):

[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = "America/Chicago"

for a little more detail:

http://forums.modx.com/thread/33294/solved-warning-strtotime-function-strtotime-in-evo-1-01-on-php-5-3-0

vulgarbulgar
  • 729
  • 1
  • 7
  • 14
1

It sounds like there may be more than one php.ini on your system and the wrong one has been edited. I believe it is possible to specify a different php.ini directory per vhost with suPHP (using the suPHP_ConfigPath option).

There are a couple of options open to you. Firstly: you could (as the error message suggested) use:

date_default_timezone_set()

However, this does make your code less portable.

Alternatively you can double-check which php.ini file is being loaded when the script executes by creating a phpinfo page; i.e. just a web-accessible php file with the following content:

<?php
phpinfo();

View the page and look for the sections marked "Loaded Configuration File" and "Additional .ini files parsed". These should tell you which ini files you need to be editing.

It is worth checking all of the files listed as any of them may contain misspelt date.timezone settings that are overriding the one you have set.

Tom Hudson
  • 366
  • 1
  • 4
0

I fixed this by removing the quotes around the string value.

So,

date.timezone = "Europe/London"

becomes...

date.timezone = Europe/London

and the problem went away. I am a little concerned by this though.

David
  • 1
  • 1
0

I just solved this problem. At first, I thought the wrong php.ini was being read. After many checks, I found out the problem. This was, that I had an extra ' in the middle of the php.ini, so it was getting an error there, preventing the rest from loading. I fixed it, and it works perfect. You can see if there's any error by running the following: php -i | grep php.ini | tail -n2
Mariano