Zen Cart Logo
Forums / Zen Cart Release Announcements / date.timezone patch for v1.5.1/1.5.0/1.3.9 on PHP 5.3/5.4/5.5

date.timezone patch for v1.5.1/1.5.0/1.3.9 on PHP 5.3/5.4/5.5

Locked

Views: 26,194

Results 1 to 2 of 2
This thread is locked. New replies are disabled.
16 Jun 2013, 9:39 PM
#1
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

date.timezone patch for v1.5.1/1.5.0/1.3.9 on PHP 5.3/5.4/5.5

PHP 5.3 changed the PHP configuration requirements for date/timezone handling, and tons of PHP servers are incorrectly configured with invalid (usually missing or number-based instead of name-based) timezones.

If you are getting the following error, you can fix it by creating your own patch files as described below:

Symptom:
PHP 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 misspelled the timezone identifier. We selected 'America/New_York' for 'EDT/-5.0/EST' instead in ...

Solution:
Place the following code into 2 NEW files you'll create on your server:

  1. /includes/extra_configures/datetime_patch_for_v151_or_older.php
  2. /YOUR_ADMIN_FOLDER/includes/extra_configures/datetime_patch_for_v151_or_older.php
    NOTE: BOTH files require the same content:
<?php
/*
 * Get time zone info from PHP config
*/
if (version_compare(PHP_VERSION, 5.3, '>='))
{
  @date_default_timezone_set(date_default_timezone_get());
}

IF THAT DOES NOT WORK, THEN ...
"Plan B" would be to replace date_default_timezone_get() above with your actual timezone like this:

@date_default_timezone_set('Europe/Oslo');

IF THAT STILL DOES NOT WORK ... THEN YOU HAVE A BIGGER SERVER PROBLEM!
If you continue to get errors related to date.timezone after following these instructions, then you must contact your hosting company for help in properly setting date.timezone in your server's PHP configuration. You will have to solve it with their help.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

25 Jan 2015, 9:07 PM
#2
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: date.timezone patch for v1.5.1/1.5.0/1.3.9 on PHP 5.3/5.4/5.5

Some people have reported that the above approach did not work satisfactorily for them.
So here's an alternative:

A. If you're already using ZC v1.5.2 or newer, the following IS ALREADY BUILT-IN! So skip step B here, and go to the instructions in C below.

B. Delete the 2 files from the previous post above, and create the following 2 files instead:

  1. /admin/includes/extra_configures/use_catalog_time_zone.php
<?php
/**
 * @package admin
 * @copyright Copyright 2003-2013 Zen Cart Development Team
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version GIT: $Id: Author: DrByte  Sat Nov 2 01:21:28 2013 -0400 New in v1.5.2 $
 */
// get time zone settings from catalog-side file
include (DIR_FS_CATALOG . '/includes/extra_configures/set_time_zone.php');
  1. /includes/extra_configures/set_time_zone.php
<?php
/**
 * @package initSystem
 * @copyright Copyright 2003-2013 Zen Cart Development Team
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version GIT: $Id: Author: DrByte  Sat Nov 2 01:21:28 2013 -0400 New in v1.5.2 $
 */
/*
 * Set time zone
*/
if (version_compare(PHP_VERSION, 5.3, '>='))
{
  // put your timezone here. Refer to http://www.php.net/manual/en/timezones.php
[B]  $TZ = '';  // eg: 'Europe/Oslo'[/B]






  /**
   * MAKE NO CHANGES BELOW THIS LINE
   *
   * The following will take the timezone you specified above and apply it in your store.
   * If you didn't specify one, it will try to use the setting from your server's PHP configuration
   */
  if ($TZ == '') {
    $TZ = date_default_timezone_get();
  }
  if ($TZ != '') {
    putenv('TZ=' . $TZ);
    @date_default_timezone_set($TZ);
  }
}

The line highlighted in red is described below:

C. To set your store to use the correct timezone, simply edit the line shown in red above (in set_time_zone.php), to reflect your desired timezone.

If you're using a Zen Cart version older than v1.5.4, it's time to upgrade!

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.