21,893
社区成员




$url = "http://www.google.com.hk/search?q=%E5%9B%BD%E5%AE%B6%E7%94%B5%E7%BD%91&hl=zh-CN&newwindow=1&safe=strict&biw=1419&bih=715&prmdo=1&tbs=frm:1&ei=1attTe7qO4jKvQOszpzbBA&start=10&sa=N";
//$url = 'http://www.baidu.com';
echo '##1';
$page = file_get_contents($url);
var_dump($page);
echo '##2';
header("Content-type:text/html;charset=gbk");
$surl = 'http://www.google.com.hk/';
$url = "http://www.google.com.hk/search?q=%E5%9B%BD%E5%AE%B6%E7%94%B5%E7%BD%91&hl=zh-CN&newwindow=1&safe=strict&biw=1419&bih=715&prmdo=1&tbs=frm:1&ei=1attTe7qO4jKvQOszpzbBA&start=10&sa=N";
$cookie_file = dirname(__FILE__) . "/cookie.txt";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url); //设置要获取的url
curl_setopt($ch, CURLOPT_REFERER, $surl); //设置向前连接
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file); //执行后返回cookie
$contents = curl_exec($ch);
curl_close($ch);
echo $contents;
header("Content-type:text/html;charset=gbk");
$surl = 'http://www.google.com.hk/';
$url = "http://www.google.com.hk/search?q=%E5%9B%BD%E5%AE%B6%E7%94%B5%E7%BD%91&hl=zh-CN&newwindow=1&safe=strict&biw=1419&bih=715&prmdo=1&tbs=frm:1&ei=1attTe7qO4jKvQOszpzbBA&start=10&sa=N";
$cookie_file = dirname(__FILE__)."/cookie.txt";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $surl);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_close($ch);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_REFERER, $surl);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
$contents = curl_exec($ch);
curl_close($ch);
echo $contents ;
header("Content-type:text/html;charset=gbk");
$surl = 'http://www.google.com.hk/';
$url = "http://www.google.com.hk/search?q=%E5%9B%BD%E5%AE%B6%E7%94%B5%E7%BD%91&hl=zh-CN&newwindow=1&safe=strict&biw=1419&bih=715&prmdo=1&tbs=frm:1&ei=1attTe7qO4jKvQOszpzbBA&start=10&sa=N";
$cookie_file = dirname(__FILE__)."/cookie.txt";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $surl);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_exec($ch);//少了这句。。
curl_close($ch);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_REFERER, $surl);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
$contents = curl_exec($ch);
curl_close($ch);
echo $contents ;
header("Content-type:text/html;charset=big5");//加个头
$url = "http://www.google.com.hk/search?q=%E5%9B%BD%E5%AE%B6%E7%94%B5%E7%BD%91"; //直接跟关键词即可,没必要复制url链接。
//$url = 'http://www.baidu.com';
echo '##1';
$page = file_get_contents($url);
var_dump($page);