I am using the following on all my index.php
files to include a global footer:
<?php include($_SERVER['DOCUMENT_ROOT'].'/_footer.php'); ?>
The _footer.php file itself doesn't have much content apart from the PHP to return the current year:
<div class="footer">
<p id="left">Company Address</p>
<p id="right">Copyright <?php echo date("Y"); ?> Company Incorporated</p>
</div>
</div> <!-- end .wrapper -->
</body>
</html>
While the above code works when uploaded to the web server, it does not work in my localhost (Mac OS X with Coda 2) and I get the error message:
WARNING: DATE() [ FUNCTION.DATE ]: IT IS NOT SAFE TO RELY ON THE SYSTEM'S TIMEZONE SETTINGS. YOU ARE REQUIRED TO USE THE DATE.TIMEZONE SETTING 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 'UTC' FOR 'GMT/0.0/NO DST' INSTEAD IN /USERS/USER/SITES/COMPANY/EXAMPLE.COM/_FOOTER.PHP ON LINE 3
I would posit that it wouldn't be such a problem to set the timezone or not (since it's a simple function designed to show the year only), but it breaks the design of the footer when local testing:
All the text (eg "COPYRIGHT") is meant to be inside that yellow box.
What should I do in this case?
Have you read the error message? It quite clearly states that it is not safe to rely on the system's timezone settings, and that you are required to use the Date.Timezone
setting or the date_default_timezone_set()
function.
So, do one or the other.
Either a) Modify your php.ini
to have this:
date.timezone=Europe/London
or b) Call this above your call to date()
(or in a globally included script):
date_default_timezone_set('Europe/London');
Obviously, Europe/London
should be replaced with your actual timezone identifier of which a list is available here: http://php.net/manual/en/timezones.php
Just an additional note, if it's not showing on your server it's because either display_errors
is disabled, or your error reporting level is lower than it is in your development machine, which it certainly should be.
Read and understand how the errors work in php: http://php.net/manual/en/function.error-reporting.php . Make yourself a method of errors that doesn't include showing it onyour page, but send it to file.
fix the problem by doing what the warning says: see http://php.net/manual/en/function.date-default-timezone-set.php
if you want to be crude, put an @
in front of the call that produces the warning. It surpresses errors/warnings.
I would turn your html "inside-out" to solve your problem this way:
<?php
date_default_timezone_set('America/Chicago');
$displayDate = date("Y");
print <<<HERE
<div class="footer">
<p id="left">Company Address</p>
<p id="right">Copyright $displayDate Company Incorporated</p>
</div>
HERE;
?>
You can do more complex things to setup your date text and get it "just right".
Set date_default_timezone_set
http://php.net/manual/en/function.date-default-timezone-set.php
请在php.ini date.timezone中设置默认时区
eg: date.timezone = = America/Los_Angeles
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.