开发者

retrieve cookie using curl, and set that cookie to user

I access the page with this code. Then it gets the cookie, This is my curl code:

$开发者_如何转开发ckfile = tempnam ("/tmp", "CURLCOOKIE"); 

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$url);
    curl_setopt($ch, CURLOPT_USERAGENT,"Mozilla/3.0 (compatible; MSIE 5.01; Windows NT 5.0)");
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("REMOTE_ADDR: ".$_SERVER['REMOTE_ADDR'], "HTTP_X_FORWARDED_FOR: ".$_SERVER['REMOTE_ADDR']));
    curl_setopt($ch, CURLOPT_COOKIEJAR, $ckfile);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    $result = curl_exec ($ch);

I want to set the information stored in the ckfile to the user.

How can I do that?


You can pick up the cookie value from the cookie file you have mentioned in your curl code and by using setcookie() send that value to the user.

However if you think that the cookie will be usable on the site you have opened with CURL, it would be incorrect. Any cookie you create on your site will be ONLY accessible on your site and would have no bearing on any other site.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜