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?
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:
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