php 远程获取cookie

方法一:通过curl远程获取

$ch = curl_init('http://wap.cmread.com/iread/wml/l/readbook.jsp?nid=350413155&bid=363585095&cid=363585106&cm=M3020052');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
preg_match('/^Set-Cookie: (.*?);/m', curl_exec($ch), $m);
var_dump(parse_url($m[1]));

 

方法二:file_get_contents获得cookie

$url = 'http://wap.cmread.com/iread/wml/p/flsy.jsp?nid=6882046&pg=109980&lab=25859&cm=M3020052&t1=15763';
$file = file_get_contents ( $url , false );
preg_match_all( "/Set-Cookie:(.*?)\r\n/" , implode( "\r\n" , $http_response_header ), $cookies );
if (!empty($cookies[1])) {
var_dump($cookies[1]);
var_dump(substr($cookies[1][0], 12, 33) );
}

 

你可能感兴趣的:(cookie)