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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
seodevhead
Forum Regular
Posts: 705
Joined: Sat Oct 08, 2005 8:18 pm
Location: Windermere, FL

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

Post 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
User avatar
seodevhead
Forum Regular
Posts: 705
Joined: Sat Oct 08, 2005 8:18 pm
Location: Windermere, FL

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

Post 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'
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

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

Post 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.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

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

Post 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.
User avatar
lafever
Forum Commoner
Posts: 99
Joined: Sat Apr 05, 2008 2:03 pm
Location: Taylor, MI

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

Post 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
 
Post Reply