$url = "Http://www.baidu.com/s?wd=csdn"; $header = Array ( ' user-agent:mozilla/5.0 (Windows NT 5.1) applewebkit/ 537.36 (khtml, like Gecko) chrome/33.0.1750.146 safari/537.36 '); $ch = Curl_init (); $timeout = 10; curl_setopt ($ch, Curlopt_url, $url), curl_setopt ($ch, Curlopt_httpheader, $header); curl_setopt ($ch, curlopt_returnt Ransfer, 1); curl_setopt ($ch, Curlopt_connecttimeout, $timeout); $content = Curl_exec ($ch); if ($content = = FALSE) {
echo "Error:". Curl_error ($ch);} Curl_close ($ch); Echo $content;
Reply to discussion (solution)
Forge Referer URLs
The 1 floor has been made very clear.
Forge Referer URLs
curl_setopt ($ch, Curlopt_referer, ' http://www.baidu.com/');
No way.
You have to understand that when the picture is displayed, it's not PHP's curl request, but the browser's request. Browser sent the request, your current URL is what domain name such as www.devtest.com, then the picture of refer is what. So I'm sure I can't see the picture.
One way is, all the pictures of Baidu, you replace the access to write a PHP such as url/image.php?baidu_url=******,***** is the real picture address, and then your image.php in call curl and add refer to crawl.
Http://i7.baidu.com/it/u=1366412274,1504179524&fm=96&s=E840F41219BFE0C844FC8DCA0300F0B3
You are not able to access the code directly (403 error)
But with the cookies you get when you visit Http://www.baidu.com/s?wd=csdn, you can access them in code.
Thank you, we've solved it.
Header (' Content-type:image/jpeg '); $ch = Curl_init (); $url = "Http://t12.baidu.com/it/u=1464136568,2122787600&fm =58&s=3ff6e816c0b4ff90237dc7c40200f024 "; curl_setopt ($ch, Curlopt_url, $url) curl_setopt ($ch, CURLOPT_REFERER, ' http://www.baidu.com '); $content = curl_exec ($ch); Curl_close ($ch); Echo $content;