3

I'm new to cURL and I'm trying to access my ebay account using php cURL, I have an existing code but ebay doesn't seem to let me log in using cURL. It just displays the login page when I echo the result.

$username="testtest"; 
$password="testtest"; 
$url="https://signin.ebay.co.uk/ws/eBayISAPI.dll?co_partnerId=2&siteid=3&UsingSSL=1"; 

$gacookie="/var/www/barcode/cookie/cookie.txt";
$postdata = 'userid='. $username .':pass='. $password;

$ch = curl_init(); 
curl_setopt ($ch, CURLOPT_URL, $url); 
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
curl_setopt ($ch, CURLOPT_TIMEOUT, 60); 
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt ($ch, CURLOPT_COOKIEJAR, $gacookie); 
curl_setopt ($ch, CURLOPT_COOKIEFILE, $gacookie);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); 
curl_setopt ($ch, CURLOPT_POST, 1); 
$AskApache_result = curl_exec ($ch); 
curl_close($ch); 

echo $AskApache_result;

Is it possible to login to ebay using php cURL by username and password or tokens?

Cray
  • 2,774
  • 7
  • 22
  • 32
Lao
  • 168
  • 1
  • 8

2 Answers2

1

Post data should look like this:

foo=bar&field=value

In your case:

$postdata = 'userid='. $username .'&pass='. $password;

Skpd
  • 670
  • 3
  • 17
  • Hi Skpd, still doesn't let me log in. – Lao Oct 31 '12 at 07:06
  • It was just a data format. Fields that you need exactly you can find on https://signin.ebay.co.uk page in `
    ` tag. You need to send all inputs with proper data.
    – Skpd Oct 31 '12 at 08:44
  • 1
    won't work if $username/$password contains special characters like &= or space. use urlencode() or http_build_query(), `$postdata = 'userid='. urlencode($username) .'&pass='. urlencode($password);` – hanshenrik Aug 24 '19 at 14:39
0

try adding the following code

curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);    

and troubleshoot further with

var_dump($AskApache_result);
echo curl_error($ch);
000
  • 3,976
  • 4
  • 25
  • 39
  • tried but didn't work. Also echo curl_error($ch); didn't display any errors. – Lao Oct 31 '12 at 07:13
  • check this post if it helps..http://stackoverflow.com/questions/10307744/how-to-login-in-with-curl-and-ssl-and-cookies – 000 Oct 31 '12 at 07:27