CURL crazyness

Discussion in 'PHP' started by trixs, Aug 20, 2008.

  1. #1
    Hi everyone,

    I use curl often in my tiny web empire and every now and then I get an odd result that looks like this:

    ������å½[iz&v=ý+¢³M‘”™••u`H¦PU<4Çd7Er8³Û3HDeFU™•‘“‡"‹²€Æ°1Æ.à…¯eÆX–<ÍÑZë…u±ò�6е¾—®4‚o4CðÏðó¼ïwŠCfeO-¹GbeD|ñÅw|Ïû¼7?½ýåÞÓöèNÔ›õ£GßÛ}p/ªÕï¯î5·ŸÞŽ~ðùÓ‡¢æÒrôtÆé$Íq¿Ñ¸óE-ªõ&“áv£ñòåË¥—«KÙè°ñôqãŸÕäÍæg}ܹԝtk­OnÊ_õã[inmméÝ5ÚîǃÃ[µƒQ-ò¿ºéèV­?

    This is the result from trying to grab a web page with curl. Now this is only a small portion - in reality it is very long jumble.

    Here is the code used to grab it:

    <?php
            $spiderme = "http://fr.wikipedia.org/wiki/Victor-Emmanuel_II";
          
          
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL,$spiderme);  // url set
       //   curl_setopt($ch, CURLOPT_USERAGENT, $this->agent);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); // get the response as a string from curl_exec(), rather than echoing it
            curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1); // don't use a cached version of the url
           // curl_setopt($ch, CURLOPT_TIMEOUT, 5);  //max time before time out
    
            $html = curl_exec ($ch);
            $intReturnCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
            curl_close($ch);
            
            echo $html;
    ?>
    PHP:

    Anyone know why this is happening? Does this page do the same for you?
     
    trixs, Aug 20, 2008 IP
  2. William[ws]

    William[ws] Peon

    Messages:
    47
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try added Header false might work as one of the curlopts
     
    William[ws], Aug 20, 2008 IP
  3. trixs

    trixs Peon

    Messages:
    111
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for reply!

    I have tried messing with headers and cookies and still get the issue. Heres an example with headers and cookies

    <?php
            $spiderme = "http://fr.wikipedia.org/wiki/Victor-Emmanuel_II";
          
            $cookie = "/home/user/tmp/cookie.tx";
            
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL,$spiderme);  // url set
       //   curl_setopt($ch, CURLOPT_USERAGENT, $this->agent);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); // get the response as a string from curl_exec(), rather than echoing it
            curl_setopt($ch, CURLOPT_HEADER, 0);
            curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie); // sets the cookie file location
            curl_setopt($ch, CURLOPT_COOKIE, $cookie); // use the cookie we have on file
            curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1); // don't use a cached version of the url
           // curl_setopt($ch, CURLOPT_TIMEOUT, 5);  //max time before time out
    
            $html = curl_exec ($ch);
            $intReturnCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
            curl_close($ch);
            
            echo $html;
    ?>
    PHP:
     
    trixs, Aug 20, 2008 IP
  4. William[ws]

    William[ws] Peon

    Messages:
    47
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Post a link where i can see the output live.
     
    William[ws], Aug 20, 2008 IP
  5. trixs

    trixs Peon

    Messages:
    111
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Well that's interesting - I tried it on an offsite host and it works fine. So for some reason some pages do not curl well running form my home server but works fine on my offsite server. Maybe I will just reroute when the issue happens :)
     
    trixs, Aug 20, 2008 IP
  6. William[ws]

    William[ws] Peon

    Messages:
    47
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Sounds like a plan lol
     
    William[ws], Aug 20, 2008 IP
    trixs likes this.