This article mainly introduces curl data acquisition, simulated login, and POST data. For more information, see
This article mainly introduces curl data acquisition, simulated login, and POST data. For more information, see
Let's talk a little bit about code.
The Code is as follows:
/********************** Curl series *************** ********/
// Obtain data directly through curl (including POST and HEADER)
/*
* $ Url: if it is not an array, http is used. If it is an array, https is used.
* $ Header: header file
* $ Post: array format submitted in post Mode
* $ Cookies: 0 does not have a cookie by default, 1 is set, 2 is get
*/
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;
}