您好,欢迎访问一九零五行业门户网

获取远程服务器网站源文件二种方法

代码如下 复制代码
function getsourcecode($q){
return @file_get_contents($q);
}
//用curl获取网站源文件
function c_getpagecode($c_url,$p_i=0){
 $user_agent = mozilla/4.0;
 $proxy[0] = http://211.155.231.208:80; //浙江省杭州市 电信idc机房
 $proxy[1] = http://210.51.10.197:8888; //北京市 通泰大厦网通idc机房
 $ch = curl_init();
 curl_setopt ($ch, curlopt_proxy, $proxy[$p_i]);
 curl_setopt ($ch, curlopt_url, $c_url);
 curl_setopt ($ch, curlopt_useragent, $user_agent);
 //curl_setopt ($ch, curlopt_cookiejar, c:cookie.txt);
 curl_setopt ($ch, curlopt_header, 0);
 curl_setopt ($ch, curlopt_returntransfer, 1);
 curl_setopt ($ch, curlopt_followlocation, 1);
 curl_setopt ($ch, curlopt_timeout, 120);
 $result = curl_exec ($ch);
 curl_close($ch);
 return $result;
}
//实例应用
 代码如下 复制代码
$url ='http://mb.111cn.net';
//$body = getsourcecode( $url);
//echo $body; //就把mb.111cn.net内容全部采集到了本地
//再来看一下用curl获取网站源码文件函数实例
echo c_getpagecode($url);
其它类似信息

推荐信息