Steve has moved my web hosting to a new server in the last 24 hours. He's notified me of a warning that is being repeatedly issued on one of my php scripts. When I say my they haven't been written by me, just a kindly forum member a few years ago.
This is the warning message...
PHP Warning: getdate(): 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 the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /home/cheadlehulmeweather/www/NOAA-reports.php on line 161
Looking at that php file I have the following for the time zone...
$ourTZ = 'Europe/London'; // set your timezone - see: http://php.net/manual/en/timezones.php
And a little further on is this code...
<?php
if (!isset($PHP_SELF) ) { $PHP_SELF = $_SERVER['PHP_SELF']; }
putenv("TZ=$ourTZ");
$now = getdate();
print "<!-- now\n" . print_r($now,true) . " -->\n";
$now_month = sprintf("%02d",$now['mon']);
$now_year = $now['year'];
$prior_month = $now['mon'] - 1;
$prior_year = $now['year'];
$last_year = $prior_year -1;
if ($prior_month < 1) { $prior_month = 12; $prior_year--; }
$prior_month = sprintf("%02d",$prior_month);
print "<!-- parms: yr = '$yr' | mo = '$mo' -->\n";
print "<!-- now = '$now_month'-'$now_year' | prior = '$prior_month'-'$prior_year' -->\n";
I have highlighted the only reference to that variable.
Can anyone help in resolving this warning please? The code does contain the correct time zone entry for my location so I'm a bit mystified.
Welcome to the Cumulus Support forum.
Latest Cumulus MX V3 release 3.28.6 (build 3283) - 21 March 2024
Cumulus MX V4 beta test release 4.0.0 (build 4019) - 03 April 2024
Legacy Cumulus 1 release 1.9.4 (build 1099) - 28 November 2014
(a patch is available for 1.9.4 build 1099 that extends the date range of drop-down menus to 2030)
Download the Software (Cumulus MX / Cumulus 1 and other related items) from the Wiki
Latest Cumulus MX V3 release 3.28.6 (build 3283) - 21 March 2024
Cumulus MX V4 beta test release 4.0.0 (build 4019) - 03 April 2024
Legacy Cumulus 1 release 1.9.4 (build 1099) - 28 November 2014
(a patch is available for 1.9.4 build 1099 that extends the date range of drop-down menus to 2030)
Download the Software (Cumulus MX / Cumulus 1 and other related items) from the Wiki
Time Zone warning message in NOAA php script - help please!
Moderator: saratogaWX
-
- Posts: 3390
- Joined: Wed 06 May 2009 6:29 pm
- Weather Station: Davis VP2 with Daytime FARS
- Operating System: Windows XP SP3
- Location: Cheadle Hulme, Cheshire, England
- Contact:
- mcrossley
- Posts: 12756
- Joined: Thu 07 Jan 2010 9:44 pm
- Weather Station: Davis VP2/WLL
- Operating System: Bullseye Lite rPi
- Location: Wilmslow, Cheshire, UK
- Contact:
Re: Time Zone warning message in NOAA php script - help plea
Ray, try changing it to...
Code: Select all
date_default_timezone_set($ourTZ);
- saratogaWX
- Posts: 1185
- Joined: Wed 06 May 2009 5:02 am
- Weather Station: Davis Vantage Pro Plus
- Operating System: Windows 10 Professional
- Location: Saratoga, CA, USA
- Contact:
Re: Time Zone warning message in NOAA php script - help plea
The updated version of my scripts include the code so it handles both situations
Code: Select all
if (!function_exists('date_default_timezone_set')) {
if (! ini_get('safe_mode') ) {
putenv("TZ=$ourTZ"); // set our timezone for 'as of' date on file
}
// print "<!-- using putenv(\"TZ=". $SITE['tz']. "\") -->\n";
} else {
date_default_timezone_set($ourTZ);
// print "<!-- using date_default_timezone_set(\"". $ourTZ. "\") -->\n";
}
-
- Posts: 3390
- Joined: Wed 06 May 2009 6:29 pm
- Weather Station: Davis VP2 with Daytime FARS
- Operating System: Windows XP SP3
- Location: Cheadle Hulme, Cheshire, England
- Contact:
Re: Time Zone warning message in NOAA php script - help plea
Mark,mcrossley wrote:Ray, try changing it to...Code: Select all
date_default_timezone_set($ourTZ);
Sorry, change which bit to the above? In the declaration section up at the top or further down in the code?
Ken, you'll appreciate this code was modified for me as my knowledge of php is zero. Preferably I want to change the minimum required to resolve the warning message.
- mcrossley
- Posts: 12756
- Joined: Thu 07 Jan 2010 9:44 pm
- Weather Station: Davis VP2/WLL
- Operating System: Bullseye Lite rPi
- Location: Wilmslow, Cheshire, UK
- Contact:
Re: Time Zone warning message in NOAA php script - help plea
Just replace the red bit you highlighted. Ken's code is a good general solution, but the one line change should get you going.
-
- Posts: 3390
- Joined: Wed 06 May 2009 6:29 pm
- Weather Station: Davis VP2 with Daytime FARS
- Operating System: Windows XP SP3
- Location: Cheadle Hulme, Cheshire, England
- Contact:
Re: Time Zone warning message in NOAA php script - help plea
Thanks Mark. I've changed that line and uploaded the new version to the web server.
I'll await Steve's reply tomorrow.
I'll await Steve's reply tomorrow.
- steve
- Cumulus Author
- Posts: 26701
- Joined: Mon 02 Jun 2008 6:49 pm
- Weather Station: None
- Operating System: None
- Location: Vienne, France
- Contact:
Re: Time Zone warning message in NOAA php script - help plea
That's done the trick - thanks, everyone
Steve