Jump to content

need help debugging code


rndilger

Recommended Posts

Hello, I'm trying to debug code that was working before my webhost upgraded servers. Even though no code was changed, it no longer works. The page I'm referring to can be seen here: http://www.indianasheep.com/news. The script that runs on this page is supposed to collect rss news feeds and display on the items that contain certain keywords. I did not build the overall system, it is FeedForAll (http://www.feedforall.com/); I'm just trying to get the system working again.

 

Basically, on the news page, I have it iterate through a txt file that contains all my rss feeds that need to be checked. Here is the code that does this:

 

$filename = "/home/indiana/public_html/scripts/rss/rssfeeds.txt";
									$fp = @fopen($filename, 'rb');
									if ($fp) { $rssfeeds = explode("\n", fread($fp, filesize($filename))); }
									foreach ($rssfeeds as $a) {
										include ("http://www.indianasheep.com/scripts/rss/rss2html.php?TEMPLATE=output.php&XMLFILE=".$a."&MAXITEMS=10");
									}
									unset($a); 

 

What the include does is pass variables to the actual rss2html.php file using output.php as the template. Here is the code from output.php:

 

<table width="600">
<tr><td>
	<table bgcolor='#666666' border='0' cellpadding='0' cellspacing='0'>
		<tr>
			<td width='26' height='28'><img src='http://www.indianasheep.com/images/tl.png' width='26' height='28' border='0'></td>
			<td rowspan='2' align='center' width='548'><a href='~~~FeedLink~~~' style='text-decoration:none;' target='_blank'><h3 style='color:#FFF; padding:5px;'>~~~FeedTitle~~~</h3></a></td>
			<td width='26' height='28'><img src='http://www.indianasheep.com/images/tr.png' width='26' height='28' border='0'></td>
		</tr>
		<tr>
			<td width='26' height='30'><img src='http://www.indianasheep.com/images/bl.png' width='26' height='30' border='0'></td>
			<td width='26' height='30'><img src='http://www.indianasheep.com/images/br.png' width='26' height='30' border='0'></td>
		</tr>
	</table>
</td></tr>
~~~BeginItemsRecord~~~
<?php

$displayItem = 0;
$file_key = "/home/indiana/public_html/scripts/rss/keywords.txt";
$fp = @fopen($file_key, 'rb');
if ($fp) { $keywords = explode("\n", fread($fp, filesize($file_key))); }	
foreach ($keywords as $b) {
	if ((stristr("~~~ItemTitle~~~", $b) !== FALSE) || (stristr("~~~ItemDescription~~~", $b) !== FALSE)) {
		$displayItem = 1;
	}
}

if ($displayItem == 1) {
	echo "<tr><td><br>~~~ItemPubLongDate~~~</td></tr>
  	<tr><td style='padding-bottom:5px;'><a href='~~~ItemLink~~~' target='_blank'>~~~ItemTitle~~~</a></td></tr>";
}
?>
~~~EndItemsRecord~~~

</table>
<br /><br />

 

So this just fills in a table with the rss feeds and the pertinent items that match keywords. The funny variables (e.g., ~~~ItemTitle~~~) are specific for the FeedForAll system, these must be used this way.

 

If you look at the original news page, it appears to run none of the code. However, if I insert echo statements into the foreach loop, it gets outputted and I've verified that the txt file with rssfeeds is being read correctly (I can output everything from that array). So it appears that the information is not being passed to output.php.

 

Here is a link to what it is supposed to output: http://www.indianasheep.com/scripts/rss/rss2html.php?TEMPLATE=output.php&XMLFILE=http://ars.usda.gov/news/rss/rss.htm&MAXITEMS=10. You'll notice that everything works, so I'm confused as to why the foreach loops are no longer working?!

 

On a second note, I'd also like to modify this code to ONLY show those rss feeds for which news items contain specified keywords. When the code was working, it would still display a heading for each of the rss feeds specified in the txt file even if they didn't have any items that matched the keywords. I would really love if someone had input on this as well.

 

Any advice?

 

Thanks,

 

Ryan

Link to comment
Share on other sites

It's entirely possible your host doesn't allow fopen() but you'd also want to make sure your absolute paths are correct (/home/indiana/etc...).

 

Sorry, had to step out for a meeting. I checked the phpinfo on my server and it says "allow_url_fopen" is set to 'on' in both local and master. Also, I can't imagine that absolute paths would stop working all of a sudden. Other than checking them over, is there any way to debug this?

 

Ryan

Link to comment
Share on other sites

No errors upon un-suppressing errors for fopen. And am I able to view the php.ini configuration file? I don't think I have access to it's location (/usr/local/lib/php.ini). My host swears they haven't changed anything on their end, except for the switch to a new server.

 

Ryan

Link to comment
Share on other sites

Great suggestion, I will try that. But I also just realized that it probably shouldn't be the fopen function that is failing. As I mentioned in my original post, I was able to output the contents of the array that contains the rssfeeds (see news page now: http://www.indianasheep.com/news) that shows output using:

 

$filename = "/home/indiana/public_html/scripts/rss/rssfeeds.txt";
									$fp = fopen($filename, 'rb');
									if ($fp) { $rssfeeds = explode("\n", fread($fp, filesize($filename))); }
									foreach ($rssfeeds as $a) {
										echo $a."<br>";
										//include ("http://www.indianasheep.com/scripts/rss/rss2html.php?TEMPLATE=output.php&XMLFILE=".$a."&MAXITEMS=10");
									}
									unset($a); 

 

Therefore, it appears that the file is read just fine, but maybe the variables aren't being passed to the code in the include file? I'm not sure.

 

Ryan

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.