Get the remote server Web site source files two ways

Source: Internet
Author: User
Tags curl
The code is as follows Copy Code

function Getsourcecode ($q) {

Return @file_get_contents ($q);

}
Get web site source files with Curl
function C_getpagecode ($c _url, $p _i=0) {
$user _agent = "mozilla/4.0";
$proxy [0] = "http://211.155.231.208:80"; Zhejiang province Hangzhou Telecom IDC Room
$proxy [1] = "http://210.51.10.197:8888"; Beijing Tong Tai Building netcom IDC Room
$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;
}

Instance Application

The code is as follows Copy Code
$url = ' http://mb.111cn.net ';
$body = Getsourcecode ($url);


Echo $body; The mb.111cn.net content was collected locally

Let's take a look at that. Get web site source file Function example with Curl
echo C_getpagecode ($url);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.