Retriving a rss feed with jfeed and curl?

344 Views Asked by At

I have been fighting with this for hours now I am trying to retrive a rss feed from maxhire: rsslink, parse the content and display it using jfeed. now i am aware of the ajax not allowing for cross domain and i have been using the proxy.php that jfeed comes packaged with, but to no avail it just tells me there are to many redirects in the url so i have increased them like so:

<?php
header('Content-type: text/html');
$context = array(
    'http'=>array('max_redirects' => 99)
);
$context = stream_context_create($context);
// hand over the context to fopen()
$handle = fopen($_REQUEST['url'], "r", false, $context);

if ($handle) {
    while (!feof($handle)) {
        $buffer = fgets($handle, 4096);
        echo $buffer;
    }
    fclose($handle);
}
?>

but still no luck it just returns a message telling me that the object has been moved. So i have moved on to using curl like so:

$ch = curl_init('http://www.maxhire.net/cp/?EC5A6C361E43515B7A591C6539&L=EN');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);

$result = curl_exec($ch);
var_dump($result);

to retrive the xml page locally but it just returns the same error the object has moved:

<body>string(237) "<title>Object moved</title>
<h2>Object moved to <a href="/cp/?EC5A6C361E43515B7A591C6539&amp;L=EN&amp;AspxAutoDetectCookieSupport=1&amp;AspxAutoDetectCookieSupport=1">here</a>.</h2>

"
</body>

then redirects me to a url locally with : &AspxAutoDetectCookieSupport=1 added to the end. Can someone please explain what i'm doing wrong?

1

There are 1 best solutions below

0
On

Right I managed to get curl working by faking the useragent and the cookies and i am using a custom metafield in wordpress to assign the url like so:

    <?php
  $mykey_values = get_post_custom_values('maxhireurl');
  foreach ( $mykey_values as $key => $value ) {  
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $value);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.6 (KHTML, like Gecko) Chrome/16.0.897.0 Safari/535.6'); 
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_REFERER, "http://www.maxhire.net");
$html = curl_exec($ch);
curl_close($ch);
echo $html;
}
?>