Home  >  Article  >  Backend Development  >  Sample code for using curl to grab remote page content_PHP tutorial

Sample code for using curl to grab remote page content_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 14:59:44670browse

The most basic operation is as follows

Copy the code The code is as follows:

$curlPost = 'a=1&b =2';//Simulated POST data
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-FORWARDED-FOR:0.0.0.0', 'CLIENT-IP:0.0. 0.0')); //Construct IP
curl_setopt($ch, CURLOPT_REFERER, "http://www.jb51.net/"); //Construct source
curl_setopt($ch, CURLOPT_URL, 'http ://www.jb51.net');//Page path to be crawled
curl_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 the variable
curl_close($ch)

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/328109.htmlTechArticleThe most basic operation is as follows. Copy the code as follows: $curlPost = 'a=1//Simulate POST data $ch = curl_init(); curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-FORWARDED-FOR:0.0.0.0', 'CLI...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn