【问题标题】:Curl - cookie issue (header doen't set cookie to browser)Curl - cookie 问题(标头未将 cookie 设置为浏览器)
【发布时间】:2014-11-14 08:37:01
【问题描述】:

我使用这个脚本:

 <?php
/*
This script is an example of using curl in php to log into on one page and 
then get another page passing all cookies from the first page along with you.
If this script was a bit more advanced it might trick the server into 
thinking its netscape and even pass a fake referer, yo look like it surfed 
from a local page.
*/

$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEJAR, "/tmp/cookieFileName");
curl_setopt($ch, CURLOPT_URL,"http://www.myterminal.com/checkpwd.asp");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "UserID=username&password=passwd");

ob_start();      // prevent any output
curl_exec ($ch); // execute the curl command
ob_end_clean();  // stop preventing output

curl_close ($ch);
unset($ch);

$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_COOKIEFILE, "/tmp/cookieFileName");
curl_setopt($ch, CURLOPT_URL,"http://www.myterminal.com/list.asp");

$buf2 = curl_exec ($ch);

curl_close ($ch);

echo "<PRE>".htmlentities($buf2);
?>

当我运行这个脚本时,我收到了这个:

HTTP/1.1 429 Cache-Control: private Content-Length: 54 Content-Type: text/html Server: Microsoft-IIS/7.5 Set-Cookie:uzytkownikl=0908098d7a1e8c36969eaf195536d47915eaaac1a8392cac3b2776e9290e9
888;Path=/;Domain=example.pl Set-Cookie: ASP.NET_SessionId=4jrpnvd3xd2g1zayp5kss443; path=/; HttpOnly X-AspNetMvc-Version: 4.0 X-Powered-By: ASP.NET X-Powered-By: ARR/2.5 X-Powered-By: ASP.NET Date: Thu, 18 Sep 2014 20:34:29 GMT The error module does not recognize this error.

Set-cookie 不起作用。没有任何 cookie 被添加到浏览器中。 有没有办法解决它?我需要在一个页面上登录,然后从第一页获取另一个传递所有 cookie 的页面

【问题讨论】:

    标签: php curl cookies header


    【解决方案1】:

    我认为你的 /tmp/ 文件没有写权限 让它可写然后它会发送cookies

    【讨论】:

    • 该文件是可写的,cookie 已保存但不发送到浏览器。
    • cookie 文件是否保存在 /tmp/ 文件夹中?
    猜你喜欢
    • 2018-10-26
    • 2011-08-28
    • 2021-03-10
    • 2015-04-18
    • 2018-10-26
    • 2014-08-24
    • 2019-04-26
    • 2017-01-31
    相关资源
    最近更新 更多