2011-12-12 121 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是正确的;这个答案很难在网上找到。谢谢 –