Home >Backend Development >PHP Tutorial >PHP obtains detailed explanation of web pages through cURl library function_PHP tutorial
I recently worked on a small project that used the cURl library function. I found some information from the Internet, referred to a foreign blog and official manual, and summarized it.
function get_web_page( $url )
{
$options = array(
CURLOPT_RETURNTRANSFER => true, // return web page Return to web page
CURLOPT_HEADER => false, // Do not return header 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 reply 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 text:
http://nadeausoftware.com/articles/2007/06/php_tip_how_get_web_page_using_curl