Two methods for obtaining Remote Server website source files-PHP source code

Source: Internet
Author: User
Tags server website
Ec (2); & nbsp; copy the code functiongetsourcecode ($ q) {& nbsp; return @ file_get_contents ($ q );} use curl to obtain the website source file functionc_getpagecode ($ c_url, $ p_i0) {& nbsp; $ user_agent & quot script ec (2); script

The Code is as follows:

Function getsourcecode ($ q ){

Return @ file_get_contents ($ q );

}
// Use curl to obtain the website source file
Function c_getpagecode ($ c_url, $ p_ I = 0 ){
$ User_agent = "mozilla/4.0 ";
$ Proxy [0] = "http: // 211.155.231.208: 80"; // Hangzhou Telecom idc data center, Zhejiang Province
$ Proxy [1] = "http: // 210.51.10.197: 8888"; // idc of Beijing tongtai tower Netcom
$ 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:
$ Url = 'HTTP: // mb.111cn.net ';
// $ Body = getsourcecode ($ url );


// Echo $ body; // collect all the content of mb.111cn.net to the local device.

// Take a look at the function instance for getting the website source code file 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.