How does Curl's cookie work? The Novice has a headache, and curl has too many parameters, and the cookie section involves 4 of them.
Of course, the manual has written that Curl's cookie is 3, but it doesn't have a header parameter, it can contain cookies.
Curl is very useful. The main thing is to be familiar with the usage of curl_setopt.
curl_setopt ($ch, Curlopt_cookie, $cookie);
The value of the cookie here is to be used, separate, rather than &. Also do not need to use UrlEncode coding, of course, the code is better.
$cookie = "A=b;c=d;name= Fangshiyu";
Note that when using this, not in curl_setopt ($ch, Curlopt_httpheader, $header);
The $header contains the cookie parameters, otherwise it overlaps, causing the cookie to occur in unforeseen circumstances.
<? Php$url = "http://www.test.com/zzzz.php"; $post _data = Array ( "foo" =< "Bar", "Query" =< "Nettuts", " Action "=<"), $cookie _jar_index = ' f:/js/test/cookie.txt '; $cookie = "A=b;c=d;name= Fangshiyu"; $ch = Curl_init (); curl_setopt ($ch, Curlopt_url, $url); curl_setopt ($ch, Curlopt_returntransfer, 1);//We are in post data Oh! curl_setopt ($ch, Curlopt_post, 1);//Add the POST variables curl_setopt ($ch, Curlopt_postfields, $post _data); curl_setopt ($ch, Curlopt_cookie, $cookie); $output = Curl_exec ($ch); Curl_close ($ch); Echo $output;
Attach the code used to analyze cookies in IE
< phpfunction Join_cookie ($cook) {foreach ($cook as $k =< $v) {$d [] =$ K. " = ". $v; } $data = Implode (";", $d); return $data;} function Pase_cookie ($cookFile, $encode =true) {$cookie = file_get_contents ($cookFile); $citem = Explode ("*\n", $cookie) , foreach ($citem as $c) {list ($ckey, $cvalue) = explode ("\ n", $c), if ($ckey! = ") $cook [$ckey] = $cvalue;} return $cook;}