-1

I'm trying to prevent CURL from storing the cookie session in a file. But I need these cookies for a second request. So I try a solution to get the cookie in a variable, but when I use "CURLOPT_HEADER true", I do not get the answer from the web service I need. Do you know how I could do this or if I could store my cookie in a file other than the file?

I used this to get the cookie on a variable.

how to get the cookies from a php curl into a variable

So I would like to have a response with the web service answer and the cookie that I could re-use (with CURLOPT_COOKIE I think).

Thank you

1 Answers1

0

I solve my problem by using regex on the request result. and use CURLOPT_COOKIE.

// Execute the request
$response = curl_exec($ch);
// Extract the cookie from the answer
preg_match_all('/^Set-Cookie:\s*([^;]*)/mi', $response, $matches);
$cookies = $matches[1][0];
// Extract the server response from the answer
preg_match_all('/text\/html\s*(.*)/m', $response, $matches);
$serverResponse = json_decode($matches[1][0]);