简体   繁体   English

使用curl检索cookie,并将该cookie设置为用户

[英]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: 然后获取cookie,这是我的curl代码:

$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. 我想将存储在ckfile中的信息设置给用户。

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. 您可以从卷曲代码中提到的cookie文件中获取cookie值,并使用setcookie()将其发送给用户。

However if you think that the cookie will be usable on the site you have opened with CURL, it would be incorrect. 但是,如果您认为该cookie在通过CURL打开的网站上可以使用,那将是不正确的。 Any cookie you create on your site will be ONLY accessible on your site and would have no bearing on any other site. 您在网站上创建的任何Cookie都只能在您的网站上访问,并且与其他任何网站都没有关系。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM