Hi, I have been having issues with getting a php script to work on my hosting service. I previously shared a MediaTemple hosting service which the exact script worked fine. Now since moving hosting providers this script refuses to work. The script I am using is the http://www.feedforall.com/free-php-script.htm and this is the script on my site: http://meh626.com/dev2/index.php if you want to read the script you can view a .txt file of it here: http://meh626.com/dev2/indexscript.txt I have managed to get it partially working (it came up with an error before) the issue now is that it's not placing the XML file information on the template. If you want to know what I have done to get it to partially work or get a bit more background info, visit this thread which I made on another forum: http://forums.mactalk.com.au/28/67959-php-script-server-issues.html I have been in contact with my hosting providers and they have found nothing to why it doesn't work. If there is anyone here experienced with php and web servers that might be able to provide some information, it would be greatly appreciated. Thanks, Meh 626
its about external fopen requests which facilitates to read external pages. That feature is disabled in most of the shared hostings.
A feature called allow_url_fopen should be enabled in your hosting configuration. allow_url_fopen check to see if allow_url_fopen is enabled. If enabled, allow_url_fopen allows PHP's file functions -- such as file_get_contents() and the include and require statements -- can retrieve data from remote locations, like an FTP or web site. Programmers frequently forget this and don't do proper input filtering when passing user-provided data to these functions, opening them up to code injection vulnerabilities. A large number of code injection vulnerabilities reported in PHP-based web applications are caused by the combination of enabling allow_url_fopen and bad input filtering. allow_url_fopen is on by default. If it is off, You should enable allow_url_fopen in the php.ini file: ; Enable allow_url_fopen allow_url_fopen = 'on' The setting can also be enabled in apache's httpd.conf file: # allow_url_fopen php_flag allow_url_fopen on
This is because your script is taking more time then allowed 1 minute. Your server may be slow. Please post the line number 900 to 1024 here.
The modified script (that partially works): GLOBAL $limitItemDescriptionLength; GLOBAL $LongDateFormat; GLOBAL $ShortDateFormat; GLOBAL $LongTimeFormat; GLOBAL $ShortTimeFormat; GLOBAL $XMLfilename; $item = FeedForAll_rss2html_str_replace("~~~ItemTitle~~~", FeedForAll_rss2html_limitLength($currentItem->title, $limitItemTitleLength), $source); $item = FeedForAll_rss2html_str_replace("~~~ItemDescription~~~", FeedForAll_rss2html_limitLength($currentItem->description, $limitItemDescriptionLength), $item); $item = FeedForAll_rss2html_str_replace("~~~ItemEnclosureLengthFormatted~~~", FeedForAll_rss2html_sizeToString($currentItem->enclosureLength), $item); $item = FeedForAll_rss2html_str_replace("~~~ItemPubLongDate~~~", date($LongDateFormat, $currentItem->pubDate_t), $item); $item = FeedForAll_rss2html_str_replace("~~~ItemPubShortDate~~~", date($ShortDateFormat, $currentItem->pubDate_t), $item); $item = FeedForAll_rss2html_str_replace("~~~ItemPubLongTime~~~", date($LongTimeFormat, $currentItem->pubDate_t), $item); $item = FeedForAll_rss2html_str_replace("~~~ItemPubShortTime~~~", date($ShortTimeFormat, $currentItem->pubDate_t), $item); $knownFields = $currentItem->getArrayOfFields(); foreach ($knownFields as $field) { $item = FeedForAll_rss2html_str_replace($field, $currentItem->getValueOf($field), $item); } $item = FeedForAll_rss2html_CreateUniqueLink($currentItem->title, $currentItem->description, $currentItem->link, $currentItem->guid, $XMLfilename, $item); if (FeedForAll_parseExtensions() === TRUE) { $item = FeedForAll_parseExtensions_replaceInItem($currentItem, $item); } return FeedForAll_rss2html_AddIdentity($item); } } // // Allow access to the number of times that will be processed in the feed $template = FeedForAll_rss2html_str_replace("~~~NumberOfFeedItems~~~", min(abs($FeedMaxItems), count($rss_parser->Items)), $template); // // Find the string, if it exists, between the ~~~EndItemsRecord~~~ and ~~~BeginItemsRecord~~~ // if ((strstr($template, "~~~BeginItemsRecord~~~")) !== FALSE) { $match = NULL; $allitems = NULL; $loop_limit = min(abs($FeedMaxItems), count($rss_parser->Items)); if (($parts = split("~~~BeginItemsRecord~~~", $template)) !== FALSE) { if (($parts = split("~~~EndItemsRecord~~~", $parts[1])) !== FALSE) { $WholeBlock = $parts[0]; // // Check for ~~~BeginAlternateItemsRecord~~~ // if (strstr($WholeBlock, "~~~BeginAlternateItemsRecord~~~")) { $parts = split("~~~BeginAlternateItemsRecord~~~", $WholeBlock); $block1 = $parts[0]; $block2 = $parts[1]; } else { $block1 = $WholeBlock; $block2 = $WholeBlock; } if ($FeedMaxItems < 0) { for ($x = count($rss_parser->Items)-1; $x >= count($rss_parser->Items) + $FeedMaxItems; $x--) { $allitems .= FeedForALL_rss2html_replaceInItem($block1, $rss_parser->Items[$x]); $x--; if ($x >= count($rss_parser->Items) + $FeedMaxItems) { // // This is at least one more item so use the Alternate definition // $allitems .= FeedForALL_rss2html_replaceInItem($block2, $rss_parser->Items[$x]); } } } else { for ($x = 0; $x < $loop_limit; $x++) { if (isset($debugLevel) && ($debugLevel >= 2)) { echo "DIAG: Doing item fillin, \$x = $x; \$loop_limit = $loop_limit<br>\n"; } $allitems .= FeedForALL_rss2html_replaceInItem($block1, $rss_parser->Items[$x]); $x++; if ($x < $loop_limit) { // // This is at least one more item so use the Alternate definition // if (isset($debugLevel) && ($debugLevel >= 2)) { echo "DIAG: Doing item fillin, \$x = $x; \$loop_limit = $loop_limit<br>\n"; } $allitems .= FeedForALL_rss2html_replaceInItem($block2, $rss_parser->Items[$x]); } } } $template = str_replace("~~~BeginItemsRecord~~~".$WholeBlock."~~~EndItemsRecord~~~", $allitems, $template); } } } // Since ' is not HTML, but is XML convert. $template = str_replace("'", "'", $template); echo($template); die(); if (!headers_sent()) { // Send the Content-Type to force $destinationEncoding header("Content-Type: text/html; charset=$destinationEncoding"); } $resultHTML = FeedForAll_rss2html_pro($template); if (isset($outputCacheTTL) && function_exists("FeedForAll_scripts_writeOutputCacheFile")) { FeedForAll_scripts_writeOutputCacheFile($XMLfilename, $TEMPLATEfilename, $resultHTML); } } } } else { if (!headers_sent()) { // Send the Content-Type to force $destinationEncoding header("Content-Type: text/html; charset=$destinationEncoding"); } echo "<html><head><title>rss2html.php URL tool</title><meta http-equiv=\"content-type\" content=\"text/html;charset=$destinationEncoding\"></head><body bgcolor=\"#EEEEFF\">\n"; // // We are in "buildURL" mode to help create properly encoded URLs to pass to rss2html.php $_xml = ""; if (isset($_POST["XML"])) { $_xml = $_POST["XML"]; } $_template = ""; if (isset($_POST["TEMPLATE"])) { $_template = $_POST["TEMPLATE"]; } $_maxitems = ""; if (isset($_POST["MAXITEMS"])) { $_maxitems = $_POST["MAXITEMS"]; } $_nofutureitems = ""; PHP: The original script: GLOBAL $limitItemTitleLength; GLOBAL $limitItemDescriptionLength; GLOBAL $LongDateFormat; GLOBAL $ShortDateFormat; GLOBAL $LongTimeFormat; GLOBAL $ShortTimeFormat; GLOBAL $XMLfilename; $item = FeedForAll_rss2html_str_replace("~~~ItemTitle~~~", FeedForAll_rss2html_limitLength($currentItem->title, $limitItemTitleLength), $source); $item = FeedForAll_rss2html_str_replace("~~~ItemDescription~~~", FeedForAll_rss2html_limitLength($currentItem->description, $limitItemDescriptionLength), $item); $item = FeedForAll_rss2html_str_replace("~~~ItemEnclosureLengthFormatted~~~", FeedForAll_rss2html_sizeToString($currentItem->enclosureLength), $item); $item = FeedForAll_rss2html_str_replace("~~~ItemPubLongDate~~~", date($LongDateFormat, $currentItem->pubDate_t), $item); $item = FeedForAll_rss2html_str_replace("~~~ItemPubShortDate~~~", date($ShortDateFormat, $currentItem->pubDate_t), $item); $item = FeedForAll_rss2html_str_replace("~~~ItemPubLongTime~~~", date($LongTimeFormat, $currentItem->pubDate_t), $item); $item = FeedForAll_rss2html_str_replace("~~~ItemPubShortTime~~~", date($ShortTimeFormat, $currentItem->pubDate_t), $item); $knownFields = $currentItem->getArrayOfFields(); foreach ($knownFields as $field) { $item = FeedForAll_rss2html_str_replace($field, $currentItem->getValueOf($field), $item); } $item = FeedForAll_rss2html_CreateUniqueLink($currentItem->title, $currentItem->description, $currentItem->link, $currentItem->guid, $XMLfilename, $item); if (FeedForAll_parseExtensions() === TRUE) { $item = FeedForAll_parseExtensions_replaceInItem($currentItem, $item); } return FeedForAll_rss2html_AddIdentity($item); } } // // Allow access to the number of times that will be processed in the feed $template = FeedForAll_rss2html_str_replace("~~~NumberOfFeedItems~~~", min(abs($FeedMaxItems), count($rss_parser->Items)), $template); // // Find the string, if it exists, between the ~~~EndItemsRecord~~~ and ~~~BeginItemsRecord~~~ // while ((strstr($template, "~~~BeginItemsRecord~~~")) !== FALSE) { $match = NULL; $allitems = NULL; $loop_limit = min(abs($FeedMaxItems), count($rss_parser->Items)); if (($parts = split("~~~BeginItemsRecord~~~", $template)) !== FALSE) { if (($parts = split("~~~EndItemsRecord~~~", $parts[1])) !== FALSE) { $WholeBlock = $parts[0]; // // Check for ~~~BeginAlternateItemsRecord~~~ // if (strstr($WholeBlock, "~~~BeginAlternateItemsRecord~~~")) { $parts = split("~~~BeginAlternateItemsRecord~~~", $WholeBlock); $block1 = $parts[0]; $block2 = $parts[1]; } else { $block1 = $WholeBlock; $block2 = $WholeBlock; } if ($FeedMaxItems < 0) { for ($x = count($rss_parser->Items)-1; $x >= count($rss_parser->Items) + $FeedMaxItems; $x--) { $allitems .= FeedForALL_rss2html_replaceInItem($block1, $rss_parser->Items[$x]); $x--; if ($x >= count($rss_parser->Items) + $FeedMaxItems) { // // This is at least one more item so use the Alternate definition // $allitems .= FeedForALL_rss2html_replaceInItem($block2, $rss_parser->Items[$x]); } } } else { for ($x = 0; $x < $loop_limit; $x++) { if (isset($debugLevel) && ($debugLevel >= 2)) { echo "DIAG: Doing item fillin, \$x = $x; \$loop_limit = $loop_limit<br>\n"; } $allitems .= FeedForALL_rss2html_replaceInItem($block1, $rss_parser->Items[$x]); $x++; if ($x < $loop_limit) { // // This is at least one more item so use the Alternate definition // if (isset($debugLevel) && ($debugLevel >= 2)) { echo "DIAG: Doing item fillin, \$x = $x; \$loop_limit = $loop_limit<br>\n"; } $allitems .= FeedForALL_rss2html_replaceInItem($block2, $rss_parser->Items[$x]); } } } $template = str_replace("~~~BeginItemsRecord~~~".$WholeBlock."~~~EndItemsRecord~~~", $allitems, $template); } } } // Since ' is not HTML, but is XML convert. $template = str_replace("'", "'", $template); if (!headers_sent()) { // Send the Content-Type to force $destinationEncoding header("Content-Type: text/html; charset=$destinationEncoding"); } $resultHTML = FeedForAll_rss2html_pro($template); echo $resultHTML; if (isset($outputCacheTTL) && function_exists("FeedForAll_scripts_writeOutputCacheFile")) { FeedForAll_scripts_writeOutputCacheFile($XMLfilename, $TEMPLATEfilename, $resultHTML); } } } } else { if (!headers_sent()) { // Send the Content-Type to force $destinationEncoding header("Content-Type: text/html; charset=$destinationEncoding"); } echo "<html><head><title>rss2html.php URL tool</title><meta http-equiv=\"content-type\" content=\"text/html;charset=$destinationEncoding\"></head><body bgcolor=\"#EEEEFF\">\n"; // // We are in "buildURL" mode to help create properly encoded URLs to pass to rss2html.php $_xml = ""; if (isset($_POST["XML"])) { $_xml = $_POST["XML"]; } $_template = ""; if (isset($_POST["TEMPLATE"])) { $_template = $_POST["TEMPLATE"]; } $_maxitems = ""; if (isset($_POST["MAXITEMS"])) { $_maxitems = $_POST["MAXITEMS"]; } PHP:
This is the line of code mentioned in the error message: $loop_limit = min(abs($FeedMaxItems), count($rss_parser->Items)); PHP: This is the block of code it's from: // Find the string, if it exists, between the ~~~EndItemsRecord~~~ and ~~~BeginItemsRecord~~~ // while ((strstr($template, "~~~BeginItemsRecord~~~")) !== FALSE) { $match = NULL; $allitems = NULL; $loop_limit = min(abs($FeedMaxItems), count($rss_parser->Items)); if (($parts = split("~~~BeginItemsRecord~~~", $template)) !== FALSE) { if (($parts = split("~~~EndItemsRecord~~~", $parts[1])) !== FALSE) { $WholeBlock = $parts[0]; PHP: This is the same block of code but from the modified script: // Find the string, if it exists, between the ~~~EndItemsRecord~~~ and ~~~BeginItemsRecord~~~ // if ((strstr($template, "~~~BeginItemsRecord~~~")) !== FALSE) { $match = NULL; $allitems = NULL; $loop_limit = min(abs($FeedMaxItems), count($rss_parser->Items)); if (($parts = split("~~~BeginItemsRecord~~~", $template)) !== FALSE) { if (($parts = split("~~~EndItemsRecord~~~", $parts[1])) !== FALSE) { $WholeBlock = $parts[0]; PHP:
Why so complicated? Maybe something like this: <?php $url = "http://feeds2.feedburner.com/2raccoon"; $file = file_get_contents($url); $xml = new SimpleXmlElement($file); foreach ($xml->channel->item as $entry){ echo "<p><a href='$entry->link' title='$entry->title'>" . $entry->title . "</p>"; } ?> PHP:
There is no error anymore. The issue I am having now is that the script is not getting the xml data from the xml file and putting it on the template page.
I have tried this code but there is an error on line 5, it says: I've only changed the '$url' to home.html