tags:

views:

52

answers:

5

I am trying to use an rss feed from a domain that does not have a crossdomain file and because of that I am going to use a web service in the middle where I will be just getting the rss feed from a url (let's say the url is: www.example.com/feed) and then just print it to a page.

The service would work like: www.mywebservice.com/feed.php?word=something) and that will just go print the rss feed for: www.example.com/feed&q=word).

I used:

<?php

$word = $_GET["word"];

$ch=curl_init("http://example.com/feed.php?word=".$word."");

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);

$data = curl_exec($ch);
curl_close($ch);

print $data;

?>

But this did not work, it gives me (SYSTEM ERROR: we're sorry but a serious error has occurred in the system). I am on shared hosting Any help?

+2  A: 

The readfile function reads a file and writes it to the output buffer.

readfile('http://example.com/feed.rss');

A URL can be used as a filename with this function if the fopen wrappers have been enabled. See fopen() for more details on how to specify the filename. See the List of Supported Protocols/Wrappers for links to information about what abilities the various wrappers have, notes on their usage, and information on any predefined variables they may provide.

If you need to do anything with the XML, use one of PHP's many XML libraries, preferably DOM, but there is also SimpleXml or XMLReader. As an alternative, you could use Zend_Feed from the Zend Framework as a standalone component to work with the RSS feed.

If you cannot enable allow_url_fopen on your server, try cURL like Matchu suggested or go with Artefacto's suggestion.

Gordon
the problem with read file is that it gives me the error (URL file-access is disabled in the server configuration). I tried it but not sure how to either fix the configuration or in fact, use something else
@use You have to enable allow_url_fopen or work around it with fsockopen/curl.
Artefacto
Please look at the edited post above, thanks for the help!
@user Write a script with only `<?php phpinfo();` and see if curl is listed there. If it's not, you cannot use it.
Artefacto
A: 

If you want to also parse XML and process it further, be sure to look into SimpleXML. Let's you parse and manipulate the feed.

DrColossos
+1  A: 

Consider doing this with mod_rewrite (using the P flag) or setting up a reverse proxy with ProxyPass.

Artefacto
+1  A: 

Since you say you can't do the fancy URL-file-opening shortcuts due to server restrictions, you will need to use PHP's cURL module to send an HTTP request.

Matchu
I am using that (please take a look at the edited post above) but it is not working for some reason.
@user220755 - sounds like the error is, in fact, serious. That code looks to me like it should work. Try talking with your hosting provider about it.
Matchu
A: 

So at the end I ended up doing this:

$word = $_GET["word"];

$url = "http://www.example.com/feed.php?q=".$word;

$curl = @curl_init ($url);

@curl_setopt ($curl, CURLOPT_HEADER, FALSE);
@curl_setopt ($curl, CURLOPT_RETURNTRANSFER, TRUE);
@curl_setopt ($curl, CURLOPT_FOLLOWLOCATION, TRUE);
@curl_setopt ($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);

$source = @curl_exec ($curl);
@curl_close ($curl);
print $source;

I hope this is considered as an answer not an edit (if an edit please tell me so I can just delete this answer and edit the post)