Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Problem with cURL/PHP

    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 Code:
    <?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($fvCURLOPT_URL$uri);
       
    curl_setopt($fvCURLOPT_HEADERfalse);
       
    curl_setopt($fvCURLOPT_RETURNTRANSFERtrue);
       
    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($chCURLOPT_URL$fav);
       
    curl_setopt($chCURLOPT_HEADERfalse);
       
    curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
       
    curl_exec($ch);
       
    $icon curl_exec($ch);
       echo 
    $icon;
       
    curl_close($ch);
       return 
    $icon;
    }

    ?>

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    Wouldn't this be easier with file_get_contents()? You probably don't need curl to perform the first function either.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •