Warning: date() It is not safe to rely on the system timezone

Warning: date() It is not safe to rely on the system timezone

Warning: 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.
divider

If after upgrading to php 5.3.x you are getting this error

Warning: 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 misspelt the timezone identifier. We selected...

Reason for this issue is that php 5.3.x requires you to set the default time-zone in your php.ini file

You have 2 option to resolve the issue.

1. Create or edit your php.ini file and add this line;

date.timezone="Europe/London"

Change the actual value according to your needs. See the php time-zone manual for information

Note: if you do not have a php.ini file in the root of your website. the site will use the global / server wide php.ini by default.
If you have some script running on your website that requires some PHP module (example ionqube) you will need to reference the location of the script in your local php.ini file or you will get an error on your site.

2. You can add a script forcing your website to read the server time-zone.

This script needs to be loaded as close to the start of the page as possible, so the easiest way to include it in all your site pages would be to include it into the database connection file.

// Force PHP 5.3.0+ to take time zone information from OS
if (version_compare(phpversion(), '5.3.0', '>='))
{
      $date_now = @date_default_timezone_set(date_default_timezone_get());
}

I have used both options and believe the second one to be the better option. It is easy to implement and requires no fiddling with the php.ini file.

Written by:  - 10 Jun, 2011