Jump to content

Script Functioning Locally but Not Online


mcatalf0221

Recommended Posts

Hello,

 

Some months ago you guys assisted me in a PHP script that would take a text file, trim up the formatting, and echo it on my page.  The following is the code:

 

<?php
$station = 'KOQU';
$metar = get_metar($station);

function get_metar($station) {

$fileName = "http://weather.noaa.gov/pub/data/observations/metar/stations/$station.TXT";
$metar = '';
$fileData = @file($fileName);  // or die('Data not available');
if ($fileData != false) {
	list($i, $date) = each($fileData); 
	$utc = strtotime(trim($date)); 
	while (list($i, $line) = each($fileData)) {
		$metar .= ' ' . trim($line);
		}
	$metar = trim(str_replace('  ', ' ', $metar));
	}
return $metar;
}
?>

<html>
<body>

<?php
echo $metar;
?>

</body>
</html>

 

The problem is that the script works on local servers (Abyss, etc.), but when I upload it to my website, the output of the weather report is blank (i.e. http://cindtronix.com/metar.php). 

 

I've researched this via search and have tried checking the character encoding, PHP version, etc. -- without luck. 

 

Is a problem with the code itself causing this to occur?

 

Thank you!

mcatalf0221

 

Link to comment
Share on other sites

The @ in front of the file() function would suppress the display or logging of any errors, such as allow_url_fopen being off.

 

No code should contain any @ (on a development system, display_errors should be on and on a live server display_errors should be off.)

Link to comment
Share on other sites

Thanks PFMaBiSmAd ... here are the errors:

 

Warning: file() [function.file]: URL file-access is disabled in the server configuration in /hermes/web09/b870/as.cindtron/public_html/metar.php on line 11

 

Warning: file(http://weather.noaa.gov/pub/data/observations/metar/stations/KOQU.TXT) [function.file]: failed to open stream: no suitable wrapper could be found in /hermes/web09/b870/as.cindtron/public_html/metar.php on line 11

 

I'm not sure how to interpret these.  Any diagnosis would be much appreciated.

 

Link to comment
Share on other sites

Good.  Remove that little section of code that I just told you put in, and replace these lines:

 

$fileName = "http://weather.noaa.gov/pub/data/observations/metar/stations/$station.TXT";
$metar = '';
$fileData = @file($fileName);

 

With:

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, "http://weather.noaa.gov/pub/data/observations/metar/stations/$station.TXT");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HEADER, false);
        $output = curl_exec($ch);
        $fileData = explode("\n", $output);

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.