卷曲 - cookie问题(标题不要将cookie设置为浏览器)

时间:2014-09-19 17:16:23

标签: php curl cookies header

我使用这个脚本:

 <?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

1 个答案:

答案 0 :(得分:0)

我认为您的/ tmp /文件没有写入权限 使它可写,然后它将发送cookie