...

View Full Version : Problem with cURL/PHP



mkay80
08-18-2007, 06:04 PM
Hi, I am facing a strange problem with curl. I am fetching two different URLs on a single page with curl in two different functions. The 1st function returns proper data but the 2nd doesn't return anything. If I comment out the 1st function then the 2nd one works nicely. I have been pulling out my hair for over 5 hours now and I need your help...



<?php
$feed_uri = 'http://www.my_server.com/mk/favicons/filename.php?feed='.urlencode('http://earthquake.usgs.gov/eqcenter/catalogs/eqs7day-M2.5.xml');
$favicon = getFaviconName($feed_uri); //This will return the favicon address for the feed. Something like http://www.santabanta.com/favicon.ico This function is working fine and returns the url properly.

preg_match('/[^.]+$/', $favicon, $matches);
$mime = 'bmp';
if ($matches[0] == 'ico') {
$mime = 'x-icon';
} else {
$mime = $matches[0];
}
header('Content-type: image/'.$mime);

echo renderFavicon($favicon); //This will fetch the image and then spit it out to the browser. This is not working, it just renders nothing. If I comment out the getFaviconName function call from above and directly pass the icon url then it works fine.
?>

<?php

function getFaviconName($uri)
{
$fv = curl_init();
curl_setopt($fv, CURLOPT_URL, $uri);
curl_setopt($fv, CURLOPT_HEADER, false);
curl_setopt($fv, CURLOPT_RETURNTRANSFER, true);
ob_start();
$ficon = curl_exec($fv);
ob_end_clean();
curl_close($fv);
return $ficon;
}

function renderFavicon($fav) {
//$favicon = 'http://www.santabanta.com/favicon.ico';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $fav);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
$icon = curl_exec($ch);
echo $icon;
curl_close($ch);
return $icon;
}

?>

Inigoesdr
08-18-2007, 06:17 PM
Wouldn't this be easier with file_get_contents()? You probably don't need curl to perform the first function either.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum