SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Evangelist
    Join Date
    Apr 2009
    Location
    South Carolina
    Posts
    458
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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 Code:
    <?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?
    Each day is a learning experience.

  2. #2
    SitePoint Guru
    Join Date
    Nov 2003
    Location
    Huntsville AL
    Posts
    699
    Mentioned
    4 Post(s)
    Tagged
    1 Thread(s)
    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.

  3. #3
    SitePoint Evangelist
    Join Date
    Apr 2009
    Location
    South Carolina
    Posts
    458
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.
    Each day is a learning experience.

  4. #4
    SitePoint Guru
    Join Date
    Nov 2003
    Location
    Huntsville AL
    Posts
    699
    Mentioned
    4 Post(s)
    Tagged
    1 Thread(s)
    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.

  5. #5
    SitePoint Evangelist
    Join Date
    Apr 2009
    Location
    South Carolina
    Posts
    458
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.
    Each day is a learning experience.

  6. #6
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    73 Post(s)
    Tagged
    0 Thread(s)

  7. #7
    SitePoint Evangelist
    Join Date
    Apr 2009
    Location
    South Carolina
    Posts
    458
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.
    Each day is a learning experience.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •