RSS2HTML php script issue

Discussion in 'PHP' started by Meh 626, Mar 5, 2009.

  1. #1
    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
     
    Meh 626, Mar 5, 2009 IP
    Masterful likes this.
  2. crivion

    crivion Notable Member

    Messages:
    1,669
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    210
    Digital Goods:
    3
    #2
    cURL must be enabled on your host - ask them for that
     
    crivion, Mar 6, 2009 IP
  3. salahsoftware.com

    salahsoftware.com Peon

    Messages:
    249
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    its about external fopen requests which facilitates to read external pages. That feature is disabled in most of the shared hostings.
     
    salahsoftware.com, Mar 6, 2009 IP
  4. Meh 626

    Meh 626 Guest

    Messages:
    20
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    cURL support is enabled. This is the php info for my site: http://meh626.com/dev2/info.php
     
    Meh 626, Mar 6, 2009 IP
  5. salahsoftware.com

    salahsoftware.com Peon

    Messages:
    249
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    ask for file open service.
     
    salahsoftware.com, Mar 6, 2009 IP
  6. Meh 626

    Meh 626 Guest

    Messages:
    20
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Could you please go into further detail so I can explain it to my web host.

    Thank you.
     
    Meh 626, Mar 6, 2009 IP
  7. salahsoftware.com

    salahsoftware.com Peon

    Messages:
    249
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    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
     
    salahsoftware.com, Mar 6, 2009 IP
  8. Meh 626

    Meh 626 Guest

    Messages:
    20
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    allow_url_fopen is on.

    Thanks for the explanation.
     
    Meh 626, Mar 6, 2009 IP
  9. salahsoftware.com

    salahsoftware.com Peon

    Messages:
    249
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Did you get any error message from the script?
     
    salahsoftware.com, Mar 6, 2009 IP
  10. Meh 626

    Meh 626 Guest

    Messages:
    20
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #10
    The original error message before I started modifying the script was:

     
    Meh 626, Mar 6, 2009 IP
  11. salahsoftware.com

    salahsoftware.com Peon

    Messages:
    249
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #11
    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.
     
    salahsoftware.com, Mar 6, 2009 IP
  12. Meh 626

    Meh 626 Guest

    Messages:
    20
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #12
    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 &apos; is not HTML, but is XML convert.
          $template = str_replace("&apos;", "'", $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 &apos; is not HTML, but is XML convert.
          $template = str_replace("&apos;", "'", $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:
     
    Meh 626, Mar 6, 2009 IP
  13. salahsoftware.com

    salahsoftware.com Peon

    Messages:
    249
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #13
    Do you get the error on the same line? please highlight the error line.
     
    salahsoftware.com, Mar 6, 2009 IP
  14. Meh 626

    Meh 626 Guest

    Messages:
    20
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #14
    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:
     
    Meh 626, Mar 7, 2009 IP
  15. Joak1m

    Joak1m Peon

    Messages:
    135
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #15
    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:
     
    Joak1m, Mar 7, 2009 IP
  16. cveks

    cveks Member

    Messages:
    141
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    28
    #16
    where is error?"
     
    cveks, Mar 7, 2009 IP
  17. Meh 626

    Meh 626 Guest

    Messages:
    20
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #17
    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.
     
    Meh 626, Mar 7, 2009 IP
  18. Meh 626

    Meh 626 Guest

    Messages:
    20
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #18
    I have tried this code but there is an error on line 5, it says:

    I've only changed the '$url' to home.html
     
    Meh 626, Mar 8, 2009 IP
  19. salahsoftware.com

    salahsoftware.com Peon

    Messages:
    249
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #19
    echo $url and tell me the output of $url
     
    salahsoftware.com, Mar 9, 2009 IP
  20. Joak1m

    Joak1m Peon

    Messages:
    135
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #20
    The $url should be a rss feed, though.
     
    Joak1m, Mar 9, 2009 IP