简体   繁体   中英

How to get Cookies content from HTTP Request Header in CURL php?

I need to get all cookie details from the http request header of an URL. How to get all cookies content using CURL PHP? Can anyone please help me.

Thank You!

Try this

$ch = curl_init('http://www.google.com/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// get headers too with this line
curl_setopt($ch, CURLOPT_HEADER, 1);
$result = curl_exec($ch);
// get cookie
preg_match('/^Set-Cookie:\s*([^;]*)/mi', $result, $m);

parse_str($m[0], $cookies);
var_dump($cookies);

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