CodeIgniter Forums

Full Version: Error : Strict Standards: date()
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

There's still a bug in the latest CI (v. 3.0.2) that was in v. 2.1.4: an error with the timezone.

When I run CI straight out of the box, if I have the log threshold to anything above 1, I get a page full of error like this one:
Strict Standards: 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 'Europe/Berlin' for 'CEST/2.0/DST' instead in home/htdocs/system/core/Log.php on line 176
(at least 15 times)

I know the way to fix this is to set the timezone in index.php:
if(ini_get('date.timezone') == '')
{
date_default_timezone_set('Europe/Paris');
}

or to whatever timezone you like from the PHP doc.

But I would have thought that would be fixed in this release of CI ! !


Cheers,
[email protected]
You have to set your timezone in your php.ini file.

It's not a bug and CI cannot do that for you because it couldn't possibly know which timezone you're in. If that was possible, PHP itself would do it instead of giving you a warning.
You could also run into this issue when running your website on a shared hosting. Not all hosting providers have the timezone set in php.ini
I have seen this on a few different hosting providers.

I just add this at the top of the index.php file
PHP Code:
/*
|---------------------------------------------------------------
| DEFAULT TIMEZONE
|---------------------------------------------------------------
| Set the default timezone for date/time functions to use if
| none is set on the server. Set it to your location
*/
if( ! ini_get('date.timezone') ) {
 
¬† ¬†date_default_timezone_set('Europe/Amsterdam');

@Martin7483: that's what I said in my first post.

@Narf: OK, I understand that's something that should be done at server level but all (shared) hosting I've used, don't do it, so may be, it should be added in the documentation/tutorial !
Just add it to the top of your index.php file like most of us do.

I did that with CI 2.1.4 at the beginning.
Most of the PHP code I've seen which has to deal with timezones at some point includes something to set the default timezone to UTC or a developer-provided value. I eventually just dumped something into Bonfire's index.php to set it to UTC if it couldn't get a default from a couple of other sensible locations (ini_get('date.timezone') or date_default_timezone_get()).

I tried to find the exact code I used as the basis for what's in Bonfire, but at this point it looks like Composer and PyroCMS don't bother checking under most conditions and just set it, expecting the developer to change it in the code as needed.