Jump to content
Larry Ullman's Book Forums

Recommended Posts

After my web hosting company (1and1.com) switched from PHP 4 to 5, a script that once returned the current year A-OK no longer works; it now generates this error message that is e-mailed to me every time a page bearing this include is accessed:

 

An error occurred in script
'----------/includes/footer.php' on line 4:

<br />date_default_timezone_get() [<a
href='function.date-default-timezone-get'>function.date-default-timezone-get</a>]:
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 'EST/-5.0/no DST'
instead
<br />Date/Time: 1-30-2013 07:51:12
<br
/><pre>Array
....

 

Here is the code, including some changes I thought should correct the error or at least suppress the error messages:

<?php
if(function_exists("date_default_timezone_set") and function_exists("date_default_timezone_get"))
@date_default_timezone_set(@date_default_timezone_get());
// date_default_timezone_set('America/New_York');

$startyear = 2009;
$currentyear = date("Y");
if ($startyear == $currentyear) {
echo 'Copyright © 2009';
} else {
echo 'Copyright © 2009 - ' . $currentyear;
}
?>
 

How can I fix this error?

Share this post


Link to post
Share on other sites

Use the line that's commented out and remove the one before it. Think about this logically: if you're getting the error message because the default time zone is not set, then calling date_default_timezone_get() won't do anything, right?

 

Also, use curly brackets! 

  • Upvote 1

Share this post


Link to post
Share on other sites

Thanks, Larry, that solved the problem. I'd previously implemented the exact changes you suggested, using date_default_timezone_set('America/New_York'); and nothing above it, but it originally did not work for well over a month. In retrospect, I suspect the problem resulted from the 1and1.com server -- one of MANY they have -- but they evidently fixed it. I told them of the error but they initially dismissed my report, which is characteristic of them.

 

BTW, if you ever start a web hosting company, I'd be your first customer and gladly pay several times what I'm paying 1and1. There must be many people like me who are frustrated with the ineptness and poor support of the major web hosting companies.

Share this post


Link to post
Share on other sites

Thanks for the nice words, Doc, although don't hold your breath for me to start doing hosting! 1 and 1, from everything I've heard, is terrible, and should be avoided.

Share this post


Link to post
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.
Note: Your post will require moderator approval before it will be visible.

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.

Loading...

×
×
  • Create New...