How to fix strange error about time zone

I have a bit of HTML that uses an include to echo the current year. It is working on all my pages (that I have checked), except one. The code I am using is

<?php
$date = getdate();
echo $date['year'];
?>

The error is:

Strict Standards: getdate() [function.getdate]: 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 in /footer.php on line 7

What I really do not understand is why, when I use an include and the code is identical, do I get the error on a single page?

Is there a setting I can make that will fix this problem?

There are some functions for intercepting errors and such but I haven’t used them in a long time.

In general, always use error_reporting(E_ALL); when in development. Very handy for catching typos. Avoid it during production as it can reveal some things about your code which could be a security risk. Plus it tends to confuse end users.

Just add date_default_timezone_set() to the top of your page. The manual lists the available time zones. You can also update php.ini or even .htaccess.

I’m guessing that the one page generating the warning has error_reporting turned on. It’s usually a good idea to also have error_reporting(E_ALL); at the top of all your pages.

You were correct. I did have error reporting set using error_reporting(E_ALL | E_STRICT); and I thought I should be commenting out error reporting once I got the page running correctly.

I have also noticed some things about logging errors, but I don’t know how to do that. It would be nice if I could find a way to have errors sent to me via email or directly to my cell phone.

Makes sense to have error reporting on while in development (which I am), and I will be sure to not have error reporting when I finish getting everything working.

It sure is great to have this forum as a source of information.

Common-PHP-Problems

StarLion,

oops - I actually have copied that and printed it. Guess I should read it through before posting a message that I already had the answer. :blush: