/* ----- Save COOKIE -----*/ $ Url = 'www .111cn.net '; // url $ Post = "id = user & pwd = 123456"; // POST data $ Cookie = tempnam ('./', 'Cookie '); // temporary cookie file $ 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 ); /* ----- Save COOKIE -----*/ $ Url = 'www .111cn.net '; // url $ Post = "id = user & pwd = 123456"; // POST data $ Cookie = tempnam ('./', 'Cookie '); // temporary cookie file $ 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 ); |