tags:

views:

20

answers:

1
<?php

ini_set("display_errors", 1); 
error_reporting(E_ALL);

define ('HOSTNAME', 'http://rss.news.yahoo.com/rss/world');

//$path = ($_POST['rss_path']) ? $_POST['rss_path'] : $_GET['rss_path'];
//$url = HOSTNAME.$path;
$url = HOSTNAME;

// Open the Curl session
$session = curl_init();
curl_setopt($session, CURLOPT_URL, $url);


// If it's a POST, put the POST data in the body
/*
if (isset($_POST['rss_path'])) {
    $postvars = '';
    while ($element = current($_POST)) {
        $postvars .= urlencode(key($_POST)).'='.urlencode($element).'&';
        next($_POST);
    }
    curl_setopt ($session, CURLOPT_POST, true);
    curl_setopt ($session, CURLOPT_POSTFIELDS, $postvars);
}
*/

curl_setopt ($session, CURLOPT_POST, true);
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);



$xml = curl_exec($session);

 if(curl_errno($session)) {
  echo 'Curl error: ' . curl_error($session);
} 



header("Content-Type: text/xml");

echo $xml;
curl_close($session);

?>

Thanks, Praveen

A: 

http://rss.news.yahoo.com/rss/world is not a hostname. The host part is rss.news.yahoo.com.

That said, your code works (what what's commented left commented). See http://codepad.viper-7.com/j1U3jC

Tim makes a good point. You should not make a POST request. Even if it "works", it interferes with the ability to cache the request.

Artefacto
Strange Thing here is the same code is working on one server (Staging server - PHP 5.2.6) and not working on the other server(production server - PHP 5.2.6). Both servers are having same config.