(I want to apologize in advance if I am posting in the wrong area; I believe the issue may be server-related but I just don’t know. I will repost in the recommended area. Thanks for looking.)
I have jumped into the first chapter of “Build Your Own Databse Driven Website with PHP and MySQL” and have come across my first minor setback. I have installed the server, database and PHP support with no trouble. When I ran the first test script I received an additional “warning” message that was not mentioned in the book. (See attached file)
The code used was the simple
echo date('l, F dS Y.');
Everything else in the file was just the standard html page markup.
I did not encounter a time zone setting during the installation of my server software, but the message indicates the issue lies in that area. Clearly I’m very new to this, and any hints or nudges in the right direction would be greatly appreciated. Thank you so much!
Still, it does throw an errors if you have error reporting on, so there must be a reason. I’ve been seeing this too, so would like to know if there’s a better way to do dates these days.
What version of PHP you are in ralph? As far as I know, the line must exist but it could be without a value assigned. I have PHP 5.3.2 and I can find the following just below the list of extensions:
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone =Asia/Katmandu
; http://php.net/date.default-latitude
;date.default_latitude = 31.7667
; http://php.net/date.default-longitude
;date.default_longitude = 35.2333
; http://php.net/date.sunrise-zenith
;date.sunrise_zenith = 90.583333
; http://php.net/date.sunset-zenith
;date.sunset_zenith = 90.583333
The value ‘Asia/Katmandu’ was set by me after the installation. I suspect you searched the whole line ‘date.timezone = UTC’, try searching only ‘date.timezone’ instead then you can find I think.
I checked php.ini on my local machine, comparing 5.2 and 5.3.
date.timezone =
appears in 5.3 but not in 5.2, so it must be new. I’ll have to check now, but it’s possible that the error message I’ve been getting (and which was reported by the OP) is only on hosts with php 5.3 installed. I’ll have to check that.
I’m on PHP 5.2.13 and my php.ini has the following, just below the list of available extensions
;;;;;;;;;;;;;;;;;;;
; Module Settings ;
;;;;;;;;;;;;;;;;;;;
[Date]
; Defines the default timezone used by the date functions
date.timezone = Australia/Queensland
I know it’s ugly, but it works
Sets the default timezone to whatever the server has configured and will set it to UTC if there is no timezone configured on your server.
I want to give a real quick Thank You! for all the fast and helpful responses. This has been a great first experience with this forum.
The issue did lie with the date.timezone line being commented out. (And I am running 5.3 – ralph I’m not sure if there is a way for me to check your page but I can try.) I just searched for date. and found it on the second one. I added America/New_York and all is well. One thing I will say, though, is that I had to restart my Apache service to see the change. Refreshing the page doesn’t do it – at least it didn’t for me. Hopefully this will help anyone else who has this problem.
SpacePhoenix thanks so much for the link to the timezones; that was a huge help! I downloaded the latest database (via PECL) but still need to look through them and figure out where they need to be installed. I’m assuming the PHP folder but not sure if it’s the root or a subfolder.
So I’m off to the next chapter! Thanks again to all of you! I’ll definitely be back again.
Immerse, I wanted to give this a shot but I am not sure where to put it. I tried it in the php file (in between the <?php… ?> tags) but that didn’t work. Should this go in the php.ini file or somewhere else?
This problem arose with I upgraded to PHP 5.3 and using function_date();
PHP Changelog
Version Description
5.0.0 E_STRICT introduced (not part of E_ALL).
5.2.0 E_RECOVERABLE_ERROR introduced.
5.3.0 E_DEPRECATED and E_USER_DEPRECATED introduced.
From memory a KLUDGE to hide this warning:
error_level(~ E_DEPRECATED);
Instead of using the KLUDGE it is better to set date_default_timezone_set(date_default_timezone_get());
Hm well I put it above the echo date line but the message only changed to include the new function as part of the error (after “Warning:”). I also went back and commented the date line in the .ini file to make sure the refreshed page was just relying on the new code. If it helps I’ve attached a screen shot of the code. Thanks for your patience with me.
// try with and without this next line remarked
// error_reporting(~ E_DEPRECATED);
echo '<br />',
date_default_timezone_get();
$result = date_default_timezone_set(date_default_timezone_get());
echo '<br />Result: ',
$result;
echo '<br />', date('l, F dS Y.');
die;
[/php