PHP function share curl way to get data simulate login POST data
- 2021-06-28 12:11:04
- OfStack
Say nothing but code directly
/********************** curl series ***********************/
// Direct Pass curl How to get data ( Contain POST , HEADER etc. )
/*
* $url: If not an array, then http; If it is an array, https
* $header: header file
* $post: post Mode submission array form
* $cookies: 0 Default None cookie,1 For Settings ,2 For acquisition
*/
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);
// belt header Mode submission
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;
}