Recently, I used the cURl library function in a small project. I found some information from the Internet and summarized it by referring to a foreign Blog and official manual. Functionget_web_page ($ url) {$ options = array (CURLOPT_RETURNTRANSFER = true, // returnwebpage returns the webpage CURLOPT_H
Recently, I used the cURl library function in a small project. I found some information from the Internet and summarized it by referring to a foreign Blog and official manual.
Function get_web_page ($ url)
{
$ Options = array (
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // no return information
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_ENCODING => "", // handle all encodings
CURLOPT_USERAGENT => "spider", // Set UserAgent
CURLOPT_AUTOREFERER => true, // set referer on redirect
CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect connection timeout
CURLOPT_TIMEOUT => 120, // timeout on response timeout
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
);
$ Ch = curl_init ($ url );
Curl_setopt_array ($ ch, $ options );
$ Content = curl_exec ($ ch );
$ Err = curl_errno ($ ch );
$ Errmsg = curl_error ($ ch );
$ Header = curl_getinfo ($ ch );
Curl_close ($ ch );
$ Header ['errno'] = $ err;
$ Header ['errmsg '] = $ errmsg;
$ Header ['content'] = $ content;
Return $ header;
}
Original English:
Http://nadeausoftware.com/articles/2007/06/php_tip_how_get_web_page_using_curl