Home > Article > Backend Development > PHP function sharing curl method to obtain data, simulate login, POST data_PHP tutorial
No further nonsense and let’s get straight to the code
//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;
}