使用curl检索cookie,并将该cookie设置为用户 [英] retrieve cookie using curl, and set that cookie to user

查看:115
本文介绍了使用curl检索cookie,并将该cookie设置为用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用此代码访问页面。然后它获取cookie
这是我的curl代码:

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);

我想将ckfile中存储的信息设置给用户。

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

我该如何做?

推荐答案

你已经在你的curl代码中提到,并使用setcookie()发送该值给用户。

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.

但是如果你认为cookie可以在网站上使用用CURL打开,这将是不正确的。您在自己网站上创建的任何Cookie只能在您的网站上访问,并且不会对任何其他网站产生影响。

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.

这篇关于使用curl检索cookie,并将该cookie设置为用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆