rndilger Posted January 12, 2009 Share Posted January 12, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/140534-need-help-debugging-code/ Share on other sites More sharing options...
bluesoul Posted January 12, 2009 Share Posted January 12, 2009 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...). Quote Link to comment https://forums.phpfreaks.com/topic/140534-need-help-debugging-code/#findComment-735427 Share on other sites More sharing options...
rndilger Posted January 12, 2009 Author Share Posted January 12, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/140534-need-help-debugging-code/#findComment-735554 Share on other sites More sharing options...
DeanWhitehouse Posted January 12, 2009 Share Posted January 12, 2009 Un suppress errors on fopen to see if their are any $fp = @fopen($filename, 'rb'); change to $fp = fopen($filename, 'rb'); Quote Link to comment https://forums.phpfreaks.com/topic/140534-need-help-debugging-code/#findComment-735558 Share on other sites More sharing options...
revraz Posted January 12, 2009 Share Posted January 12, 2009 It can be on in your PHP.INI and still be blocked by the host. Quote Link to comment https://forums.phpfreaks.com/topic/140534-need-help-debugging-code/#findComment-735574 Share on other sites More sharing options...
rndilger Posted January 12, 2009 Author Share Posted January 12, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/140534-need-help-debugging-code/#findComment-735596 Share on other sites More sharing options...
DeanWhitehouse Posted January 12, 2009 Share Posted January 12, 2009 Maybe use ini_get() http://uk.php.net/ini_get To find out if it is in the php.ini file Even better http://uk.php.net/ini_get_all Quote Link to comment https://forums.phpfreaks.com/topic/140534-need-help-debugging-code/#findComment-735597 Share on other sites More sharing options...
rndilger Posted January 12, 2009 Author Share Posted January 12, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/140534-need-help-debugging-code/#findComment-735604 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.