简体   繁体   中英

how to get cookie list from remote url using php

Does anyone knows how I could get a list of cookies for an external URL using php?

I think this could be done with cURL?

When i'm using cookiejar or using get_headers, I only see one cookie (the PHPSESSID) for example. But when you open chrome console (F12) and go to cookie storage, you see a much bigger list. Also the google analytics cookies for example. I want to be able to display that list of cookies. So also 3rd party cookies..

Is there any way to retrieve those cookies? Maybe store them temporary or something?

If I got you right & you mean getting cookies that a page sets when visiting it using cURL ,
You can use CURLOPT_COOKIEJAR option of cURL for auto manage cookies with cURL ( curl_setopt ):

$ch = curl_init($url);  
curl_setopt($ch, CURLOPT_HEADER, 1); 
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$cont = curl_exec ($ch);  
curl_close ($ch);  

Or search response header for Set-Cookie: line:
how to get the cookies from a php curl into a variable

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM