2014-09-19 74 views
0

我使用這個腳本:捲曲 - cookie的問題(標題doen't設置的cookie到瀏覽器)

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

當我運行此腳本,我recive此:

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從第一頁

回答

0

我覺得你的/ tmp /文件沒有寫權限 使其可寫,然後它會發送cookie

+0

該文件是另一頁可寫,cookie已保存,但不發送給瀏覽器。 – tangor 2014-09-20 12:01:27

+0

是保存在/ tmp /文件夾中的cookie文件嗎? – 2014-09-22 06:35:28