2011-12-12 100 views
0

我正在嘗試使用PHP CURL登錄到網站。這一切都工作正常的網站,不需要cookie和會話,但它似乎並沒有與您需要的網站,所以這裏是我的代碼我發現這個代碼here 任何幫助,這將是apritiated感謝
代碼CURL - Cookie未啓用/會話過期

<?php 

// 1 - 獲取首次登錄頁http://signin.ebay.com/aw-cgi/eBayISAPI.dll?SignIn

$ebay_user_id = "username"; // Please set your Ebay ID 
$ebay_user_password = "password"; // Please set your Ebay Password 
$cookie_file_path = "cookie.txt"; // Please set your Cookie File path 

$LOGINURL = "__"; 
$agent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)"; 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL,$LOGINURL); 
curl_setopt($ch, CURLOPT_USERAGENT, $agent); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path); 
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path); 
$result = curl_exec ($ch); 
// curl_close ($ch); 

// 2- Post Login Data to Page http://signin.ebay.com/aw-cgi/eBayISAPI.dll 

$LOGINURL = "url"; 
$POSTFIELDS = 'postfiends'; 
$reffer = "url"; 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL,$LOGINURL); 
curl_setopt($ch, CURLOPT_USERAGENT, $agent); 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS,$POSTFIELDS); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt($ch, CURLOPT_REFERER, $reffer); 
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path); 
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path); 
$result = curl_exec ($ch); 
// curl_close ($ch); 
print $result;  

?> 
+0

你的cookie.txt包含你的第一個cURL過程後的數據..? –

+0

是的一些數據被寫入cookie.txt文件 –

+0

它實際顯示什麼錯誤..? –

回答

0

http://signin.ebay.com/aw-cgi/eBayISAPI.dll不僅希望用戶名和密碼後的數據,但其他參數很好,也許你沒有考慮到這一點。使用螢火蟲的Net標籤查看傳遞的參數,並嘗試複製它。

+0

嘿,我已經確定我已經把所有的帖子參數,我正在使用httpliveheaders –

+0

@ tushar-chutani我使用捲曲做了很多工作,cookie問題通常是。 「爲了幫助社區的其他用戶(請記住,這個網站是基於共同的努力)',請解釋如何通過所有的帖子字段將解決完全不同的問題,這是你在你的問題中提到的:'cookie不是啓用/會話過期「。 THX.- –

2

也許你需要更多的選擇:

// define some HTTP headers 
$headers[] = "Accept: */*"; 
$headers[] = "Connection: Keep-Alive"; 
$headers[] = "Content-type: application/x-www-form-urlencoded;charset=UTF-8"; 

// to GET add 
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
curl_setopt($ch, CURLOPT_HEADER, 0); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);   

// to POST add 
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
curl_setopt($ch, CURLOPT_HEADER, 1); 

// check for errors before close 
$result = curl_exec($ch); 
if ($result === false) 
{ 
    echo curl_error($ch); 
} 
curl_close($ch); 

確保您$cookie_file_path文件是可寫的(如Linux)的。玩CURLOPT_SSL_VERIFYHOSTCURLOPT_SSL_VERIFYPEER

+0

NomikOS是正確的;這個答案很難在網上找到。謝謝 –