Tushar Chutani
Tushar Chutani

Reputation: 1570

CURL - cookie not enabled/session expired

I am trying to log into a website using PHP CURL. It all works fine on websites which doesn't require cookies and session but it doesn't seem to work with the websites which rquire you so here is my code I found this code over here any help on this would be apritiated thanks
Code

<?php

// 1-Get First Login Page 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;    

 ?>

Upvotes: 0

Views: 4489

Answers (2)

Igor Parra
Igor Parra

Reputation: 10348

Maybe you need more options:

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

Be sure that your $cookie_file_path file is writable (if Linux). Play with CURLOPT_SSL_VERIFYHOST and CURLOPT_SSL_VERIFYPEER.

Upvotes: 2

Nitesh
Nitesh

Reputation: 712

http://signin.ebay.com/aw-cgi/eBayISAPI.dll not only expects username and password as post data, but other parameters as well, maybe you didn't take account of that. Use Net tab on firebug to see the parameters passed, and try to duplicate it.

Upvotes: 0

Related Questions