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.p开发者_如何学JAVAhp 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.
Your server is configured in such a way that you cannot include from a remote location. This is common in shared hosting environments to help reduce server load and reduce the possibility of malicious code being accidentally executed.
However, if I understand you right, you could not just include the RSS feed using the include()
construct anyway, because it is not valid PHP code - include()
expects the path to be a valid PHP source code file. What you are doing, if your server allowed you to do it, would result in either useless output or a parse error.
You need to connect to the RSS feed (e.g. using cURL or fsockopen() depending on the level of control you want over the request to the remote site) and parse the feed data so you can output in a sensible format.
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);
?>
精彩评论