This article mainly introduces the example that curl does not use File Access cookies, and does not use COOKIEJAR or COOKIEFILE to access cookies.
The Code is as follows:
/* ----- Save COOKIE -----*/
$ Url = 'www .xxx.com '; // url
$ Post = "id = user & pwd = 123456"; // POST Data
$ Ch = curl_init ($ url); // Initialization
Curl_setopt ($ ch, CURLOPT_HEADER, 1); // output the header file information as a data stream
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1); // return the obtained output text stream
Curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ post); // send POST data
$ Content = curl_exec ($ ch); // execute curl and assign it to $ content
Preg_match ('/Set-Cookie :(. *);/iU', $ content, $ str); // Regular Expression matching
$ Cookie = $ str [1]; // obtain the COOKIE (SESSIONID)
Curl_close ($ ch); // close curl
/* ----- Use COOKIE -----*/
Curl_setopt ($ ch, CURLOPT_COOKIE, $ cookie );