<p>参考代码1:</p><pre class="brush:php;toolbar:false"><?php
//创建一个新cURL资源
$ch=curl_init();
//设置URL和相应的选项
curl_setopt($ch,CURLOPT_URL,"http://www.baidu.com/");
curl_setopt($ch,CURLOPT_HEADER,false);
//抓取URL并把它传递给浏览器
$data=curl_exec($ch);
echo$data;
//关闭cURL资源,并且释放系统资源
curl_close($ch);
?></pre><p>参考代码2:</p><pre class="brush:php;toolbar:false"><?php
$szUrl="http://www.baidu.com/";
$UserAgent='Mozilla/4.0(compatible;MSIE7.0;WindowsNT6.0;SLCC1;.NETCLR2.0.50727;.NETCLR3.0.04506;.NETCLR3.5.21022;.NETCLR1.0.3705;.NETCLR1.1.4322)';
$curl=curl_init();
curl_setopt($curl,CURLOPT_URL,$szUrl);
curl_setopt($curl,CURLOPT_HEADER,0);//0表示不输出Header,1表示输出
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,false);
curl_setopt($curl,CURLOPT_ENCODING,'');
curl_setopt($curl,CURLOPT_USERAGENT,$UserAgent);
curl_setopt($curl,CURLOPT_FOLLOWLOCATION,1);
$data=curl_exec($curl);
echo$data;
//echocurl_errno($curl);//返回0时表示程序执行成功如何从curl_errno返回值获取错误信息
exit();
?></pre>