Home >Backend Development >PHP Tutorial >PHP curl collects remote page content demo code_PHP tutorial
There are many functions in PHP that can collect remote pages. For example, file_get_contents(), fopen, file(), these functions can collect remote server data, but curl is the best for performance. It supports multi-threading.
Example
The code is as follows | Copy code | ||||
$ch = curl_init(); curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-FORWARDED-FOR:0.0.0.0', 'CLIENT-IP:0.0.0.0')); //Construct IPcurl_setopt($ch, CURLOPT_REFERER, "http://www.bkjia.com/"); //Construction origin curl_setopt($ch,CURLOPT_URL, 'http://www.bkjia.com');//Page path to be crawledcurl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_TIMEOUT, 30);curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);//post value $file_contents = curl_exec($ch);//The captured content is placed in variables |
Notes
www.bkjia.com