Murray, Utah | USA
801.265.1100


Everyone loves free stuff, here is our collection of random free things!



Full Blog Entry

Free Tutorial on Logging into eBay with PHP cURL

September 10th 2010 12:55:36 | Free Stuff
blog image for Free Tutorial on Logging into eBay with PHP cURL

The first subject that we want to go over is cURL, what is cURL?

libcurl, a library created by Daniel Stenberg, that allows you to connect and communicate to many different types of servers with many different types of protocols. libcurl currently supports the http, https, ftp, gopher, telnet, dict, file, and ldap protocols. libcurl also supports HTTPS certificates, HTTP POST, HTTP PUT, FTP uploading (this can also be done with PHP's ftp extension), HTTP form based upload, proxies, cookies, and user+password authentication.

There is so much that can be done with cURL but for now we are just going to go over how use the basics and login to eBay grabbing just about any page and saving the html as data. We can then take the data that we get, format it, convert it, add it, check it and just about anything else.

Step 1
Create your php page along with a couple functions that we are going to use:

function curl_cookie_set($submit_url)
{
	//sets the cookie file so the post function will work correctly
	$cookie_path = dirname(realpath(basename($_SERVER['PHP_SELF']))). '/cookie';	
	$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, $submit_url); 
	curl_setopt($ch, CURLOPT_USERAGENT, $agent); 
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
	curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_path); 
	curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_path); 
	$result = curl_exec ($ch); 
	curl_close ($ch); 
}
function curl_post_request($referer, $submit_url, $data, $ch)
{
	// sends a request via curl to the string specifics listed
	$cookie_path = dirname(realpath(basename($_SERVER['PHP_SELF']))). '/cookie';
	$agent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)";
	curl_setopt($ch, CURLOPT_URL, $submit_url); 
	curl_setopt($ch, CURLOPT_USERAGENT, $agent); 
	curl_setopt($ch, CURLOPT_POST, 1);  
	curl_setopt($ch, CURLOPT_POSTFIELDS, $data);  
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
	curl_setopt($ch, CURLOPT_REFERER, $referer); 
	curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_path); 
	curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_path); 
	return $result = curl_exec ($ch);
}
function curl_clean($ch)
{
	// cleans and closes the curl connection
	$cookie_path = dirname(realpath(basename($_SERVER['PHP_SELF']))). '/cookie';	
	if (file_exists($cookie_path)) { unlink($cookie_path); }
	if ($ch != '') { curl_close ($ch); }
}



Step 2
After we create the functions we want to set a couple of strings that we will be using for the functions:

set_time_limit(0); // sets the page load time to not end
$ebay_user_id = "your username"; // ebay id 
$ebay_user_password = "your pass"; // ebay password 
$debug = true;



Step 3
Now all we need to do is call our functions with the ebay start and login page, we use the start page first to set the cookies and then post our ebay_user_id and ebay_user_password inside the url as seen below:

// 1 - Get the Cookies required to login from the welcome login page 
$login_url = "http://signin.ebay.com/aw-cgi/eBayISAPI.dll?SignIn"; 
curl_cookie_set($login_url);

// 2 - Post Login Cookies and Login Information to Page Link 
$ch = curl_init(); 
$referer = $login_url; // change old start page to the referer
$submit_url = "http://signin.ebay.com/aw-cgi/eBayISAPI.dll"; 
$postfields = 'MfcISAPICommand=SignInWelcome&siteid=0&co_partnerId=2&UsingSSL=0&ru=&pp=&pa1=&pa2=&pa3=&i1=-1&pageType=-1&userid='. $ebay_user_id .'&pass='. $ebay_user_password; 
$result = curl_post_request($referer, $submit_url, $postfields, $ch);
curl_clean($ch);
print_r($result); // print the page so see if the login worked



The php project file for this tutorial can be found HERE.



 

Name (required)
Email (required - never shown publicly)
Your Comment

captcha

Categories


Blog Portal Links


Contact Us

We Are Available 24/7

Our main place of business and mailing address:

  • Duranged Design Inc
  • 4740 So. Riverside Dr.
  • Murray, Utah 84123 USA
  • 801.265.1100

Feedback Submit your ideas or ask a question

Feedback
Thank you! Message Sent!
ERROR: Message Not Sent!