Advforecast2.php help needed

I can’t get the script to work. For testing purposes I copy pasted the original Version 4.03 advforecast2, but when I access my website I get the following message:

"Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator to inform of the time the error occurred and of anything you might have done that may have caused the error.

More information about this error may be available in the server error log."

When trying to use Version 2, the forecast doesn’t update.

Any help on getting the script working again will be greatly appreciated.

What is the URL to your weather website? As of today, only advforecast2.php V4.03 will work with the https version of weather.gov/forecast.weather.gov. advforecast2.php V5.04 and V5.03 both work fine with the api.weather.gov site, but V5.05 has improved API error handling.

Did you just download the script (view https://saratoga-weather.org/advforecast2-V4.03.php?sce=view , select-all, copy, and paste)?

Same for V5.04?

Generally an ‘Internal Server Error’ indicates that there’s a syntax error somewhere in the pasted version of the script. The server’s error_log may point to the exact line having a problem.

For some reason 4.03 isn’t working properly (as the previous version did) included my .php page. Opening the page it doesn’t show any forecast or error, but if I run advforecast2.php?force=1 that works, and then a refresh of the main .php page shows the forecast - until the next time. Intranet so I can’t provide a link :frowning:

I’ve probably screwed up something related to caching but I’m posting this in case the problem sounds familiar…

I selected all and copy paste the 4.03 as it was.

My site is www.weatherpr.com - Where Im using the old version 4.02
and in www.weatherpr.com/indexoffseason.php is where i tried the 4.03 version

The 4.02 version of the script won’t work starting today (due to the NWS change to https for access, and the old script didn’t support that).

Zip up your indexoffseason.php and post the .zip … I’ll take a look. Can’t do a remote diagnosis when Server Error is all that is displayed.

When it fails, just view-source on the page and copy/post the HTML comments related to advforecast2 and I’ll take a look.

v5.05 is working fine here Union City, CA Weather - National Weather Service Forecast I also got v4.03 to work as well using the https URL.

This is what I did:
I created a test.php (NWS Forecast for San Juan PR) for the purpose of testing the new script. It has the following code:

National Weather Service Forecast for: San Juan, Puerto Rico <?php $doPrintNWS = true; require("advforecast21.php"); ?>  

Updated: <?php print $forecastupdated; ?>   <?php print $forecastwarnings; ?> <?php print "\n"; ?>   <?php print "\n"; ?>

$forecasticons[0]$forecasticons[1]$forecasticons[2]$forecasticons[3]$forecasticons[4]$forecasticons[5]$forecasticons[6]$forecasticons[7]$forecasticons[8]

$forecasttemp[0]$forecasttemp[1]$forecasttemp[2]$forecasttemp[3]$forecasttemp[4]$forecasttemp[5]$forecasttemp[6]$forecasttemp[7]$forecasttemp[8]

National Weather Service Forecast Details

I created a file which I named advforecast21.php with the script just as it is in:https://saratoga-weather.org/advforecast2-V4.03.php?sce=view

I also have a file named advforecast2.php with the old script.

The problem is that when I have the advforecast21.php (with the new script) in the test.php page the internal server error appears. Whereas when I have advforecast2.php (with the old code) the page opens with no error.

Do you think I need to contact my host godaddy?

Thank you very much for your time.

There are a couple of issues I can spot here …

  1. your current advforecast2.php script is actually Version 4.00 - 06-Jul-2015
  2. the advforecast21.php script is actually Version 5.05 - 27-Feb-2018
    so this is an apples:oranges comparison.
    Both V4.03 and 5.x versions require several things of your PHP installation that were not required by the V4.00-V4.02

First is curl capability with https support. Since you’re not running a Saratoga template, I don’t have access to the usual tool do show what version of PHP is running, and whether the needed built-in functions are available. If you are running PHP 5.2 or less, you will need to upgrade PHP to 5.3+ (preferably to 5.6+) to run either version of the script with https to weather.gov sites. If you have cPanel on your GoDaddy site, you can pick the PHP version to use.

In your test page shown above, you have

    <?php
$doPrintNWS = true;
require("advforecast21.php"); ?>

which I suggest should be

    <?php
$doPrintNWS =false;
$doIncludeNWS = true;
include_once("advforecast21.php"); ?>

since you are going to print data from the script yourself in the lines below that.

I am guessing that the Server Error is caused by an old PHP version and/or lack of curl/json. You can use this test page to see that

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Website Key Info</title>
</head>

<body>
<?php
  printInfo();
	$toCheck = array('simplexml_load_file','iconv','json_decode',
	                 'curl_init','curl_setopt','curl_exec','curl_error','curl_close');

	print "<h2>Status of needed built-in PHP functions</h2><p>\n";

	foreach ($toCheck as $n => $chkName) {
		print "function <b>$chkName</b> ";
		if(function_exists($chkName)) {
			print " is available
\n";
		} else {
			print " is <b>NOT available</b>
\n";
		}
		
	}
  print "</p>\n";

	if(function_exists('curl_version')) {
	// Get curl version array
  print "<h2>Current required cURL features status:</h2>\n";
	$version = curl_version();
	/*
	Array
	(
			[version_number] => 463623
			[age] => 3
			[features] => 1597
			[ssl_version_number] => 0
			[version] => 7.19.7
			[host] => x86_64-redhat-linux-gnu
			[ssl_version] => NSS/3.27.1
			[libz_version] => 1.2.3
			[protocols] => Array
					(
							[0] => tftp
							[1] => ftp
							[2] => telnet
							[3] => dict
							[4] => ldap
							[5] => ldaps
							[6] => http
							[7] => file
							[8] => https
							[9] => ftps
							[10] => scp
							[11] => sftp
					)
	
	)
	*/
	
		print "cURL version: <strong>".$version['version']."</strong>
\n";
		if(isset($version['ssl_version'])) {
			print "cURL SSL version: <strong>".$version['ssl_version']."</strong>
\n";
		} else {
			print "cURL SSL not enabled in PHP
\n";
		}
		if(isset($version['libz_version'])) {
			print "cURL libz version: <strong>".$version['libz_version']."</strong>
\n";
		} else {
			print "cURL libz not enabled in PHP
\n";
		}
		print "cURL protocols supported: <strong>";
		print join(', ',$version['protocols'])."</strong>
\n";
		
	
	// These are the bitfields that can be used 
	// to check for features in the curl build
	$bitfields = Array(
							'CURL_VERSION_SSL' => "SSL", 
							'CURL_VERSION_LIBZ' => "LIBZ"
							);
	
	
	foreach($bitfields as $feature => $fname)
	{
			echo $fname . ($version['features'] & constant($feature) ? ' is available' : ' is NOT AVAILABLE but REQUIRED');
			echo "
\n";
	}
  print "</p>\n";
 } else {
		  print "<h2>cURL functions are not found (but REQUIRED)</h2>\n";
}

  print "<h2>Current GD (image handling functions) status:</h2>\n";
  echo describeGDdyn();
//-------------------------------------------------

function printInfo() {
  print "<h2>Website PHP information</h2>\n";
  print "<p>\n";
  print "Webserver OS: <b>".php_uname()."</b>
\n";
  print "PHP Version: <b>".phpversion()."</b>
\n";
  if (version_compare(PHP_VERSION, '5.3.0', '<') ) {
    print "<span style=\"color: red;\"><b>NOTE: some scripts require PHP 5.3+ for proper operation.</b></span>
\n";
  }
  
  print "Document root: <b>".$_SERVER['DOCUMENT_ROOT']."</b>
\n";
  print "allow_url_fopen = <b>";
  print ini_get("allow_url_fopen")?"ON":"off";
  print "</b>
\n";
  print "allow_url_include = <b>";
  print ini_get("allow_url_include")?"ON":"off";
  print "</b>
\n";
		$streams = stream_get_wrappers();
	print "Stream support for <b>http</b> ";
	print in_array('http',$streams)?'is available':'is <b>NOT available but REQUIRED.</b>';
	print "
\n";
	print "Stream support for <b>https</b> ";
	print in_array('https',$streams)?'is available':'is <b>NOT available but REQUIRED.</b>';
	print "
\n";
	print "Streams supported: <strong>".join($streams,', ')."</strong></p>\n";

}
//-------------------------------------------------
// Retrieve information about the currently installed GD library
// script by phpnet at furp dot com (08-Dec-2004 06:59)
//   from the PHP usernotes about gd_info
function describeGDdyn() {
 echo "\n<ul><li>GD support: ";
 if(function_exists("gd_info")){
   echo "<span style=\"color:#00ff00\">is available.</span>";
   $info = gd_info();
   $keys = array_keys($info);
   for($i=0; $i<count($keys); $i++) {
	  if(is_bool($info[$keys[$i]])) {
		echo "</li>\n<li>" . $keys[$i] .": " . yesNo($info[$keys[$i]]);
	  } else {
		echo "</li>\n<li>" . $keys[$i] .": " . $info[$keys[$i]];
	  }
   }
 } else { 
   echo "<span style=\"color:#ff0000\">is NOT AVAILABLE but required.</span>"; 
 }
 echo "</li></ul>\n";
}
// ------------------------------------------------------------------

function yesNo($bool){
 if($bool) {
	 return "<span style=\"color:#00ff00\"> is available</span>";
 } else {
	 return "<span style=\"#ff0000\"> is NOT available</span>";
 }
}  

?>
</pre>
</body>
</html>

– let me know the URL of this test page on your site, and I’ll take a look.

Edit: updated the script page above to better handle missing functions.

There’s really nothing there :dontknow: Don’t worry about it Ken, has to be my problem and I have no time to play today. I’ll just start over with it tonight.

<center><a href=http://forecast.weather.gov/MapClick.php?lat=40.55763465737646&lon=-122.27096557617187&site=sto&smap=1&unit=0&lg=en&FcstType=text><font size="5" face="Times News Roman" color="0000FF"<b>NWS Zone Forecast - Northern Sacramento Valley</b></font></a></center>
  <table width="900" style="border: none;">
    <tr align="center" style="background-color: #E6E6E6;">
      <td>
      </td>
    </tr>
    <tr>
      <td align="center">Updated:           </td>
    </tr>
    <tr>
      <td align="center">&nbsp;
            <table width="100%" border="0" cellpadding="0" cellspacing="0">
              <tr valign ="top" align="center">
                  </tr>
          <tr valign ="top" align="center">
                    </tr>
        </table>
     </td>
   </tr>
</table>

Here: http://weatherpr.com/test1.html
http://weatherpr.com/test1.php

If the ‘test1.php’ page is exactly the same as the ‘test1.html’ page (just with .php extension) then it’s confirmed… your PHP installation on IIS is not working properly. You should contact your hoster’s tech support for assistance, and STRONGLY consider switching (at no charge) to Linux/Apache hosting instead. Windows/IIS/PHP is just funky enough to cause issues with scripts that work flawlessly on Linux/Apache/PHP hosting.

Try the modified script in the posting above… it better handles missing functions in PHP to display diagnostics. (or use the attached)


site-info.zip (2.77 KB)

I tried it with PHP 5.6 but had no luck. Guess I should switch to Linux then…

Just an FYI but the script does work in my Windows/IIS/PHP environment.

Do try my site-info.php script… it should work even with missing PHP functions (like curl or GD) and show what is there/missing.
Just download, unzip and upload the site-info.php to your site.

Good to know. It will work with most any PHP environment as long as cURL and the GD library are installed and functional.
Almost all of my scripts that access external websites for info now use cURL for access (or http/https stream support for images) and the GD library for image processing, so cURL and GD are ‘must haves’ for proper operation of the scripts/templates.

Here it is:

Thank you!

Ok… that works just fine, and shows that you have the necessary functions (curl, etc) and support for https enabled on your 5.6.1 PHP.

So… the server error issue will likely only be solved by checking out the message in the IIS error log for the site, or have your hoster check it for you.

You will have to run advforecast2.php V4.03 or V5.05 on your site Version 4.02 and below will not work any more with the https weather.gov site.

Thank you Ken. I will contact godaddy later today and will keep you posted. I really appreciate your support!