How to pass a cookie in PHP curl

Source: Internet
Author: User
Tags explode
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.

 

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!=& #39; & #39;), $cook [$ckey] = $cvalue;} return $cook;}  
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.