Page 1 of 1

There's gotta be a way around this...

Posted: Fri May 09, 2008 3:32 pm
by seodevhead
Hey guys...

Now that I'm strictly developing on PHP 5 servers, one error that keeps popping up on some pages that didn't pop up under PHP4 is the following:

error occurred in script '/home/user220/public_html/script.php' on line 377:
date() [function.date]: It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable 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/-4.0/DST' instead
Date/Time: 5-9-2008 16:23:37


Obviously I'm using date functions and that is what's causing this. Now to get around this, I've just been adding this to all my php pages:

Code: Select all

date_default_timezone_set('America/New_York');
But I hate having to remember to type that in on EVERY new script that I write... especially since most of my scripts don't share the same include/config files to use globally.

Is there some sort of SERVER WIDE setting I can set the timezone at? And also, is there any reprecussion for setting my scripts timezone's to America/New_York? I mean, obviously not everyone who will be using the scripts will be on Eastern Standard Time, or in America at all. What will happen to someone on say, the west coast, who uses a script that outputs time related data with the timezone set to EST?

I'm really unsure about all this, but I know one thing... it's really bugging me.

Thank you so much for any guidance on this matter... take care! :P

Re: There's gotta be a way around this...

Posted: Fri May 09, 2008 3:42 pm
by seodevhead
And I guess the other question I left out is...

Is there any harm to adding 'America/New_York' to the date.timezone directive in the php.ini since, after all, my server is on the east coast?

date.timezone='America/New_York'

Re: There's gotta be a way around this...

Posted: Fri May 09, 2008 4:00 pm
by flying_circus
I was going to say that I am with you on adding the date.timezone to the php.ini file, but then I got to thinking. What is it that PHP is trying to accomplish by not using the default system timezone? I would think it's to prevent the system admin or someone else from changing the timezone out from under you, perhaps to extend the time period on a session or something along those lines, but then what prevents them from just changing the system time? Perhaps it has more to do with some timezones that observe a daylight savings time, like the west coast?

I'm not really clear on it, but I'd do as you're thinking and put it in the php.ini file. Though, typically I include a config file in most of my projects, it wouldnt be much of a burden to put it in there either.

Re: There's gotta be a way around this...

Posted: Sat May 10, 2008 1:47 am
by RobertGonzalez
Set the value in php.ini and be happy that everything works. :)

Ok, I know that is not the "best" answer. From the manual:
The default timezone used by all date/time functions if the TZ environment variable isn't set.

Re: There's gotta be a way around this...

Posted: Sat May 10, 2008 7:57 am
by lafever
I was having the same issues with mine.

You could do the above with php.ini but unless you don't have access to it then you could do it in the .htaccess file

Code: Select all

 
php_value date.timezone America/New_York