Search code examples
phprsshostingssi

Use Server Side Includes 'include' command in the html file


Background

I am trying to include an rss feed using php into a html document

Code

<?php
include ("feed url");
?> 

I have used ssl command to successfully add the include tag in the html file like this

<!--#include virtual="rssfeed.php" -->

which works fine after editing htaccess file. Now problem is because in my php im using include ("feed url") I am getting this error:

Warning: include() [function.include]: URL file-access is disabled in the server configuration in path/rssfeed.php on line 2

Warning: include(feed url) [function.include]: failed to open stream: no suitable wrapper could be found in path/rssfeed.php on line 2

Now things to note I have tried setting php_value allow_url_fopen 1 but no luck as the files are held on third party hosting server so I do not have alot of access so they have blocked me from turning allow_url_fopen to ON for obvious reasons. So My question is how do I approch this problem ? Any directions will be greatly apperciated.

Thanks everyone for reading.


Solution

  • include "http://..." is a bad idea because the contents of http://... are evaluated as PHP code which opens your site open to attacks if someone can inject PHP code in the response of that RSS feed.

    Use curl if you want to display data from another site. From the PHP Manual example:

    <?php
    // create a new cURL resource
    $ch = curl_init();
    
    // set URL and other appropriate options
    curl_setopt($ch, CURLOPT_URL, "http://www.example.com/");
    curl_setopt($ch, CURLOPT_HEADER, 0);
    
    // grab URL and pass it to the browser
    curl_exec($ch);
    
    // close cURL resource, and free up system resources
    curl_close($ch);
    ?>