Home  >  Article  >  Backend Development  >  PHP function sharing curl method to obtain data, simulate login, POST data_PHP tutorial

PHP function sharing curl method to obtain data, simulate login, POST data_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:28:58994browse

No further nonsense and let’s get straight to the code

Copy code The code is as follows:

/************************** curl series ***********************/
//Get it directly through curl Data (including POST, HEADER, etc.)
/*
* $url: If it is not an array, it is http; if it is an array, it is https
* $header: Header file
* $post: Submit array form in post mode
* $cookies: 0 defaults to no cookie, 1 is setting, 2 is getting
*/
public function curl_allinfo($urls, $header = FALSE, $post = FALSE, $ cookies = 0) {
$url = is_array($urls) ? $urls['0'] : $urls;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

//Submit with header
if($header != FALSE){
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
}

//Post submission method
if($post != FALSE){
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}

if($cookies == 1){
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookiefile");
}else if($cookies == 2){
curl_setopt($ch, CURLOPT_COOKIEFILE , "cookiefile");
}

if(is_array($urls)){
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
}

$data = curl_exec($ch);
curl_close($ch);
return $data;
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/779570.htmlTechArticleWithout further ado, just copy the code. The code is as follows: /************************** curl series ***********************/ //Directly pass Obtain data through curl (including POST, HEADER, etc.)...
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