Cookies with cURL help

2

I need to access a certain URL and load the file 'cookies.txt' the problem is the following I access the URL normally plus the Cookies.txt does not load ...

I think the problem is here in this part

$cookiepattern = "#Set-Cookie:\s+(?<cookie>[^=]+=[^;]+)#m"; 
preg_match_all($cookiepattern, $header_content, $matches); 
$cookiesOut = implode("; ", $matches['cookie']);

$ matches ['cookie']); returns an empty array ...

'cookies.txt' file

  

Netscape HTTP Cookie File

     

This file was generated by libcurl! Edit at your own risk. .auto.com TRUE / FALSE 1452087781

asked by anonymous 05.10.2017 / 04:53

1 answer

1

Just use it:

curl_setopt($handle, CURLOPT_COOKIEFILE, 'caminho/cookie.txt')

This will load cookies that were previously saved as long as you specify the correct file. CURLOPT_COOKIEJAR will save cookies, CURLOPT_COOKIEFILE will read saved cookies, as I explained here .

If you save in this format then use this way, if you do not want to use Netscape format do not use CURLOPT_COOKIE_JAR . It does not make sense to use this if you want to extract the data in another way or edit the data that has been saved.

You can also use CURLINFO_COOKIELIST or the CURLOPT_HEADERFUNCTION to extract cookies. But since you're already saving cookies using COOKIEJAR it would be more convenient to use COOKIEFILE .

    
05.10.2017 / 07:33