Set date.timezone in PHP without using php.ini

Problem: I needed to set default timezone for a site to get Zen Cart installed. The usual way would be to call date_default_timezone_set from a globally included script, or to use the date.timezone option in a php.ini file. The problem is that I don’t have access to the php.ini file and there is no script that will be called across the board.

Fix: Turns out PHP flags can be called from .htaccess file. So assuming you are using Unix type hosting (or another server that can interpret distributed configuration files), you can add this to your .htaccess file to set the timezone:

php_value date.timezone Europe/London

Save that, upload it, and if you then look at the output of phpinfo() (create a php file with this in and upload it), you should see:

The Local Value should show what you set in the .htaccess file

2 thoughts on “Set date.timezone in PHP without using php.ini”

  1. Actually, you can do it on Zencart without having to modify php.ini or .htaccess file: Here is my non intrusive way of doing this:
    Edit this file at zc_install/includes/application_top.php and add following line on the top:
    ini_set(‘date.timezone’, ‘America/Vancouver’);
    safe it and launch your installation. Period!

Leave a Reply

Your email address will not be published. Required fields are marked *