rest - PHP using CURL: is there a way to emulate a cookie instead of saving it to a file? -
I use a restore API service that uses a variable named session_id to be stored in a cookie API And I complete it like this:
$ ch = curl_init (); // Start curl handle curl_setopt ($ ch, CURLOPT_URL, $ url); // set target URL curl_setopt ($ CH, CURLOPT_FOLLOWLOCATION, TRUE); // Redirecting curl_setopt Allow ($ CH, CURLOPT_COOKIEFILE, '. / Cookie.txt'); Curl_setopt ($ ch, CURLOPT_COOKIEJAR, '. / Cookie.txt'); Curl_setopt ($ ch, CURLOPT_POST, TRUE); // set post method curl_setopt ($ CH, CURLOPT_HTTPHEADER, $ header); // set header curl_setopt ($ CH, CURLOPT_RETURNTRANSFER, TRUE); Curl_setopt ($ CH, CURLOPT_HEADER, TRUE); // Return the headers so we can get the session ID curl_setopt ($ CH, CURLOPT_SSL_VERIFYHOST, FALSE); // Prevent unverified SSL certificate error curl_setopt ($ CH, CURLOPT_SSL_VERIFYPEER, FALSE); // Stop unverified SSL "" $ contents = curl_exec ($ ch); Curl_close ($ ch);
The problem now has been told many different times by many different users. (Many cookie files should be saved) I would just like one method to store session_id in a variable rather than reference a file. So far all my efforts have been rejected by the service. Can anyone suggest ways to store session ID and cookie information without saving a file? Note that reading session sessions is not a problem, it is back in XML for some reasons security credentials do not pass to pass it back without reference to the actual generated file. It may also be useful for more information about why this can be useful.
Cookies Required There are simple text headers sent along. Curl allows you to specify directly using CURLOPT_COOKIE
.
curl_setopt ($ ch, CURLOPT_COOKIE, 'key = value; anotherkey = anothervalue');
If you want to know what information to send, you can create your own cookie header in this way. The cookiezer / cookie option only automates parsing, saving and sending. If you do not want to write a file, then you have to do this manually (read cookie header, send to cookie header).
Comments
Post a Comment