Home > php教程 > PHP源码 > 获取远程服务器网站源文件二种方法

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

WBOY
Release: 2016-06-08 17:26:36
Original
1761 people have browsed it
<script>ec(2);</script>
 代码如下 复制代码

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);

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template