Jump to content

Recommended Posts

Posted

Is there any way of changing the server time zone? I want data to be recorded within my local time zone. And by the way, you use UTC, right?

It is set to UTC and I believe the time zone is unchangeable.

Posted

Wait sometime... It takes time for changes to take place. Also changes will take place only in your website and but in cPanel as such.

Posted

Making changes in .htaccess file (no matter if trough file manager in cPanel or trough FTP) have instant effect (unless there is some cache in your browser for example).

 

I don't remember since which version of PHP exactly (5.x), but while in older versions setting value of an environment variable "TZ" worked fine, in newer versions you have to use date_default_timezone_set, variable "TZ" won't change anything for you.

 

# For older PHP versions (up to 5.2 or 5.3):
# - in PHP script:
<?php putenv("TZ=UTC"); ?>
# - in .htaccess:
SetEnv TZ UTC
 
# For newer versions of PHP (function exists since 5.1, but required since 5.4 or so):
# - in PHP script:
<?php date_default_timezone_set('UTC'); ?>
# - in .htaccess:
php_value date.timezone 'UTC'
Posted (edited)

 

Making changes in .htaccess file (no matter if trough file manager in cPanel or trough FTP) have instant effect (unless there is some cache in your browser for example).

 

I don't remember since which version of PHP exactly (5.x), but while in older versions setting value of an environment variable "TZ" worked fine, in newer versions you have to use date_default_timezone_set, variable "TZ" won't change anything for you.

# For older PHP versions (up to 5.2 or 5.3):
# - in PHP script:
<?php putenv("TZ=UTC"); ?>
# - in .htaccess:
SetEnv TZ UTC
 
# For newer versions of PHP (function exists since 5.1, but required since 5.4 or so):
# - in PHP script:
<?php date_default_timezone_set('UTC'); ?>
# - in .htaccess:
php_value date.timezone 'UTC'

 

Ok, but how and where do I put this php script code? In all my pages, or in only one file? Inside root folder?

Edited by roguitar
Posted

It's your decision. Depends where you need it.

 

You can use .htaccess version in root folder of the domain name (public_html) for all PHP scripts or just in .htaccess inside some subfolder for PHP scripts inside that specific subfolder.

 

Or you can use PHP version, which obviously will work only inside the script itself (and override .htaccess setting). Most easy is to use one file (configuration file) included in all the other files. But if your scripts/pages are completely separate and have no common part (like for example included configuration file) then in every single .php file where you need it.

 

Most easy is to put it just in the .htaccess, of course, then you don't have to edit PHP scripts at all, if this is problem for you.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...