advforecast2.php script minor change...

I discovered I’d left out a ‘:’ in one expression, so a return to point-printable from failover zone forecast wouldn’t happen if the text of the forecast contained the word ‘location’.

Change

	  if (preg_match('/Temporary|Location/Uis',$html)) {

to

	  if (preg_match('/Temporary|Location:/Uis',$html)) {

or download the fixed version from http://saratoga-weather.org/scripts-carterlake.php#carterlake

Best regards,
Ken

btw… this version supports the /images/wtf rewrite to /forecast/images directory too.

Thanks Ken…I made note of it, and will update mine soon…Have a Good Memorial Day Weekend,…Chris

Hello All: I have been using the forecast page for some time. Today, for some reason, the forecase page was not displaying…just the link to force the page to update. When you clicked on the force update there was no change. When I saw this post I decided to correct the code.

I copied the script from the link above and made the necessary changes for my area. Once changes were complete I uploaded the php file to the same location as before. When I call up my page the PHP code is displayed. I’m not quite sure what I did wrong…

This is what I’m using to call the script into my forecast page:

<?php $doIncludeNWS = true; include("advforecast2.php"); ?>

Link to my forecast page: http://www.i40exit319weather.com/wx2.php

Thanks in advance for any assistance…Ronnie

I just put the code in a file like this:
http://jaxweather.net/AdvForecast.php

Then call it as:

<? include "http://JaxWeather.net/AdvForecast.php" ?>

and the result is:
http://jaxweather.net/5day.php

-Bob

Bob’s got the right idea.

Copy the code from http://saratoga-weather.org/advforecast2.php?sce=view and save it as advforecast2.php on your local copy of your website.

Edit your copy of advforecast2.php and change the $NOAAzone and $filename variables to have the settings for your area.

Save the edited advforecast2.php and upload it as advforecast2.php to your website.

Edit your wxlocal2.html in your \wdisplay\webfiles directory and insert

<?php
$doIncludeNWS = true;
include("advforecast2.php"); ?>

where you’d like the forecast to appear on your wx2.php page.

Save the wxlocal2.html and let WD upload it as wx2.php.

That should fix it.

Bob… you can do the same thing you suggested, but I’d recommend you change the URL to be

<? include "http://JaxWeather.net/AdvForecast.php?inc=Y" ?>

to have advforecast2.php omit the unneeded … and from the output (don’t want to confuse older browsers :slight_smile: ).

Best regards,
Ken

this is all I entered for my forecast page:

<div id="main-copy"> 
<?php $doIncludeNWS = true; include("advforecast2.php"); ?>
</div>

<!-- ##### Footer ##### -->

It will center the forecast with Icons page, and also add dark background…Most like it centered on their page, but not all add the dark background effect.it’s your choice.

Thanks for the assistance…I’ve got the page working correctly. I’m unsure what I did wrong but it’s working…

Ronnie

:smiley:

This is the point printable forecast I am using in the script:


$fileName = 'http://www.erh.noaa.gov/forecast/MapClick.php?CityName=New+Holland&state=PA&site=CTP&TextType=2';

My forecast is there, I can put that URL in a browser and it comes up. When I open my web page, the script does not use that forecast, and I can’t figure out why. It isn’t a cache issue, because I replaced the cache with a blank page and it still did not not use the forecast I have listed. It wouldn’t matter so much, but I saw today that it is screwed up.

Ahh… that fix to change

	  if (preg_match('/Temporary|Location/Uis',$html)) {

to

	  if (preg_match('/Temporary|Location:/Uis',$html)) {

actually appears twice in the code. Don’t forget to change the second one too around

if (filemtime($cacheName) + 1800 > time()) { 
      $html = implode('', file($cacheName)); 
    } else { 
      $html = fetchUrlWithoutHanging($fileName,$cacheName); 
	  if (preg_match('/Temporary|Location:/Uis',$html)) {
	     $usingFile = "(Zone forecast)";
         $html = fetchUrlWithoutHanging($backupfileName,$cacheName); 
	  }  
      $fp = fopen($cacheName, "w"); 
      $write = fputs($fp, $html); 
      fclose($fp);  } 

      // Just get the top of the NWS page for editing 

I tried that with a copy of your script and it works fine for New Holland, PA (instead of the Lancaster Country zone forecast).

Sorry, I forgot to update it in the second place too :oops: – I’ve now corrected the source on my site.

Best regards,
Ken

Thanks Ken, that did it!

I’m having the same problem. It appears only the Zone is coming up even though the url for mytown is working. I added the : in both places. What am I missing?

http://kpmcomp.com/extendedforecast2.php

Thanks

KenM

KenM (strange, I have KMT as my initials :slight_smile:

It looks like your ‘forecast.txt’ script is not being overwritten … use your IIS control panel to set the permissions for allow read/write to that file and your forecast should work ok.



<b>Warning</b>:  readfile(c:\inetpub\wwwroot) [<a href='function.readfile'>function.readfile</a>]: failed to open stream: Permission denied in <b>C:\Inetpub\wwwroot\extendedforecast2.php</b> on line <b>90</b>


was the contents of your ‘forecast.txt’ file.

Best regards,
Ken

Added those permissions but i still seem to have the same problem. You still see the same thing?

KenM

Hmmm. Now your forecast.txt file has a Carter Lake, IA forecast from Feb, 2007 – I don’t think the script can write your forecast.txt file yet. Would you mind sending me the source for your advforecast2.php file so I can take a look ( webmaster [at] saratoga-weather.org ).

Best regards,
Ken

Ken,

You are ahead of the game, yet again! I was going to try and write something for the temporary file stuff but you have already done it. I will have to review your code to see how it’s done.

Thanks for all your contributions to this board!
Jeff

I’m still working out the fact I can’t get anything to write to the forecast.txt file. IIS permissions to the file seem correct. going to try some test php to write a simple text to the file.

KenM

Ken,
You might try adding

 error_reporting(E_ALL); 

to the start of the script and see what it says. Also, your php.ini may have a setting that prevents writing local files – like Safe_mode = on , but I think it’s still the permissions.

Best regards,
Ken

Ah success… fixed my permission problems, however I still only get the default zone not my actual town forecast.

KenM

I think I’ve figured it out. Your

$filename = "http://www.erh.noaa.gov/forecast/MapClick.php?CityName=Bedford&state=NY&site=OKX&TextType=2"; 

is getting a redirect (302) to http://forecast.weather.gov/MapClick.php?CityName=Bedford&state=NY&site=OKX&TextType=2 so advforecast2.php thinks your primary (point-forecast) page is not available, so it automatically falls back to the zone-forecast page.

Try changing your code to

$filename = "http://forecast.weather.gov/MapClick.php?CityName=Bedford&state=NY&site=OKX&TextType=2";

and see if that fixes the issue.

Meanwhile, I’ll work on doing a bit of coding on it to follow the first 302 (Location: …) and refetching.

Let me know if the URL change does the trick.

Best regards,
Ken