sanchez77 Posted November 2, 2009 Share Posted November 2, 2009 Hi Everyone, For a long time i have been using fopen to read a web page and then display it on my page. But recently, it stopped working. Does anyone know an alternative that I can use? My code is below. <?php $filename="http://weather.noaa.gov/cgi-bin/fmtbltn.pl?file=forecasts/marine/coastal/an/anz451.txt"; $fp = fopen($filename,'r'); while($line=fgets($fp)) { print $line."<br>"; } fclose($fp); ?> Link to comment https://forums.phpfreaks.com/topic/179977-fopen/ Share on other sites More sharing options...
nadeemshafi9 Posted November 2, 2009 Share Posted November 2, 2009 lets just stop there a second, why has it stopped working, where is the error, you can clean out the data from now on and get rid of anything that causes the error. show us error codes you are getting etc try error_reporting(2047); before your code Link to comment https://forums.phpfreaks.com/topic/179977-fopen/#findComment-949415 Share on other sites More sharing options...
sanchez77 Posted November 2, 2009 Author Share Posted November 2, 2009 when i place the code below before it, it returns a blank page. did i write it right? do i need to add more to capture the error? error_reporting(2047); Link to comment https://forums.phpfreaks.com/topic/179977-fopen/#findComment-949428 Share on other sites More sharing options...
nadeemshafi9 Posted November 2, 2009 Share Posted November 2, 2009 is there anything included above this code in an include or somthing else or some other code ? . Link to comment https://forums.phpfreaks.com/topic/179977-fopen/#findComment-949432 Share on other sites More sharing options...
sanchez77 Posted November 2, 2009 Author Share Posted November 2, 2009 no, just the code that i wrote above. Link to comment https://forums.phpfreaks.com/topic/179977-fopen/#findComment-949434 Share on other sites More sharing options...
nadeemshafi9 Posted November 2, 2009 Share Posted November 2, 2009 type echo "hello" before everything, and see if you get a result what kind of system is this, an in house system, is this something you built or is this a third party software,framework ? Link to comment https://forums.phpfreaks.com/topic/179977-fopen/#findComment-949442 Share on other sites More sharing options...
sanchez77 Posted November 2, 2009 Author Share Posted November 2, 2009 the hellos show. it yahoo hosting, and it's just the code to read the file. nothing special. Is it possible yahoo changed security settings to not allow fopen? Link to comment https://forums.phpfreaks.com/topic/179977-fopen/#findComment-949446 Share on other sites More sharing options...
nadeemshafi9 Posted November 2, 2009 Share Posted November 2, 2009 the hellos show. it yahoo hosting, and it's just the code to read the file. nothing special. Is it possible yahoo changed security settings to not allow fopen? maybe, lets look around for another way i will get back to you brb Link to comment https://forums.phpfreaks.com/topic/179977-fopen/#findComment-949450 Share on other sites More sharing options...
nadeemshafi9 Posted November 2, 2009 Share Posted November 2, 2009 http://uk2.php.net/manual/en/function.http-request.php Link to comment https://forums.phpfreaks.com/topic/179977-fopen/#findComment-949451 Share on other sites More sharing options...
nadeemshafi9 Posted November 2, 2009 Share Posted November 2, 2009 Example 1. GET example <?php $r = new HttpRequest('http://example.com/feed.rss', HttpRequest::METH_GET); $r->setOptions(array('lastmodified' => filemtime('local.rss'))); $r->addQueryData(array('category' => 3)); try { $r->send(); if ($r->getResponseCode() == 200) { file_put_contents('local.rss', $r->getResponseBody()); } } catch (HttpException $ex) { echo $ex; } ?> Example 2. POST example <?php $r = new HttpRequest('http://example.com/form.php', HttpRequest::METH_POST); $r->setOptions(array('cookies' => array('lang' => 'de'))); $r->addPostFields(array('user' => 'mike', 'pass' => 's3c|r3t')); $r->addPostFile('image', 'profile.jpg', 'image/jpeg'); try { echo $r->send()->getBody(); } catch (HttpException $ex) { echo $ex; } ?> Link to comment https://forums.phpfreaks.com/topic/179977-fopen/#findComment-949452 Share on other sites More sharing options...
nadeemshafi9 Posted November 2, 2009 Share Posted November 2, 2009 u need to install and work out how to use PECL http://www.pecl.php.net/ Link to comment https://forums.phpfreaks.com/topic/179977-fopen/#findComment-949457 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.