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

Time Zone warning message in NOAA php script - help please!

Discussion of Ken True's web site templates

Moderator: saratogaWX

Post Reply
RayProudfoot
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:

Time Zone warning message in NOAA php script - help please!

Post by RayProudfoot »

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.
Cheers,
Ray, Cheshire.

Image
User avatar
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

Post by mcrossley »

Ray, try changing it to...

Code: Select all

date_default_timezone_set($ourTZ);
User avatar
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

Post by saratogaWX »

The updated version of my scripts include the code

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";
 }
so it handles both situations :)
RayProudfoot
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

Post by RayProudfoot »

mcrossley wrote:Ray, try changing it to...

Code: Select all

date_default_timezone_set($ourTZ);
Mark,

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.
Cheers,
Ray, Cheshire.

Image
User avatar
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

Post by mcrossley »

Just replace the red bit you highlighted. Ken's code is a good general solution, but the one line change should get you going.
RayProudfoot
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

Post by RayProudfoot »

Thanks Mark. I've changed that line and uploaded the new version to the web server.

I'll await Steve's reply tomorrow.
Cheers,
Ray, Cheshire.

Image
User avatar
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

Post by steve »

That's done the trick - thanks, everyone :)
Steve
Post Reply