Jump to content

Change Default Timezone In Php.ini


mrj

Recommended Posts

You have to do this in your scripts. I think it can be changed with set_ini...can't test though since I'm on my phone at the moment.

 

We can't change it in the ini because it there is only one php.ini that affects everyone on the server (There isn't an ini for each user).

Link to comment
Share on other sites

I used following code on htaccess file:

SetEnv TZ Asia/Dhaka

It seems worked when I view phpinfo();

But in scripts automatically using server time (maybe UTC). Any idea to set default tz for scripts?

TIA

Link to comment
Share on other sites

TZ works for older versions of PHP, in newer versions date.timezone.

In my PHP scripts I have:

putenv("TZ=UTC"); // enough for older PHP versions
date_default_timezone_set('UTC'); // required for newer PHP versions

I set it inside of my scripts as I use two or more timezones at once (for displaying two time graphs).

 

In .htaccess, If I'm right, it will looks like:

php_value date.timezone "UTC"
Link to comment
Share on other sites

 

date_default_timezone_set('UTC'); // required for newer PHP versions

 

This is the correct way to do it. I usually put stuff like this in a file called config.php and require_once it at the top of all of the php scripts in that project. That way you just have to change it in one place rather than having to change it in 15 different places.
Link to comment
Share on other sites

I already using a config file which incudes settings, header, footer, etc info for each page. Because it's too time spending to add infos in every page. I used to include config file, then call any info by functions. Thanks anyway for helping me. I will use your code to my config file. :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...