Php uses curlcookiejar, which does not rely on COOKIEJAR to obtain cookies. Php uses CURL to retrieve cookies without relying on COOKIEJAR. this example describes how php uses CURL to retrieve cookies without relying on COOKIEJAR. Share it with you for your reference. Specifically, php uses CURL to retrieve cookies without relying on COOKIEJAR. curlcookiejar
This example describes how php uses CURL to retrieve cookies without relying on COOKIEJAR. Share it with you for your reference. The specific analysis is as follows:
In PHP, the CURL class is a very awesome tool class.
The CURL class also has good support for cookies, but it is not flexible enough. Instead, it cannot be obtained using a ready-made method as a variable, but it must be implemented using the following methods.
// Save cookieto cookie.txt curl_setopt ($ ch, CURLOPT_COOKIEFILE, 'cookie.txt '); curl_setopt ($ ch, CURLOPT_COOKIEJAR, 'cookie.txt ');
First, save the COOKIE and read the file when calling it. This means that the two I/O operations are efficient, and everyone knows about the efficiency.
Is there a way to bypass writing and reading files? Do not sell off the customs, directly add the code:
// Initialize CURL $ ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL, $ url); // Obtain the header information curl_setopt ($ ch, CURLOPT_HEADER, 1 ); // return the native (Raw) output curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, true); // execute and obtain the returned result $ content = curl_exec ($ ch ); // disable CURL curl_close ($ ch); // Parse the HTTP data stream list ($ header, $ body) = explode ("\ r \ n ", $ content); // Parse COOKIE preg_match ("/set \-cookie :( [^ \ r \ n] *)/I", $ header, $ matches ); // you can directly use curl_setopt ($ ch, CURLOPT_COOKIE, $ cookie) when using CURL for later submission; $ cookie = $ matches [1];
I hope this article will help you with php programming.
Examples in this article describes how php uses CURL to retrieve cookies without relying on COOKIEJAR. Share it with you for your reference. Details...