简体   繁体   中英

Curl - cookie issue (header doen't set cookie to browser)

I use this script:

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

And when I run this script, I recive this:

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 doesn't work. None of cookie has added to browser. Is there a way to fix it? I need to login to on one page and then get another page passing all cookies from the first page

我认为您的/ tmp /文件没有写权限,使其可写,那么它将发送cookie

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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