<?php
/**
*
* This class performs cURL requests for eBay. It has built in functionality to perform the login with only the username and password required.
* @author Chris
*
*/
class ebay_curl {
/**
*
* Username used for login function. <br /> Set with setUsername function.
* @var string
*/
private $username = '';
/**
*
* Password used for login function. <br /> Set with setPassword function.
* @var string
*/
private $password = '';
/**
*
* Filesystem path used to store the cookie used in the curl requests.
* @var string
*/
private $cookie_path;
/**
*
* eBay login url used for login function.
* @var string
*/
private $login_url;
/**
*
* Useragent string sent with curl request [default to Chrome on Windows 7]
* @var string
*/
private $user_agent;
/**
*
* Referer URL sent with curl request [default to eBay login URL]
* @var string
*/
private $referer;
/**
*
* Curl object used for all cUrl I/O in this class.
* @var curl
*/
private $curl;
/**
*
* Default Constructor: Initializes all default values and removes php time limit.
*/
public function __construct() {
$this->cookie_path = '/var/www/ebay/test/ebay_mine/cookie';
$this->login_url = "http://signin.ebay.com/aw-cgi/eBayISAPI.dll";
$this->referer = "http://signin.ebay.com/aw-cgi/eBayISAPI.dll?SignIn";
$this->user_agent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.100 Safari/534.30"; //Chrome on Windows 7
set_time_limit( 0 );
}
/**
*
* Sets the username to be used for the ebay login
* @param string $username Username to passonto the ebay login
*
* @return string Current set username
*/
public function setUsername( $username ) {
return $this->username = $username;
}
/**
*
* Sets the password to be used for the ebay login function
* @param string $password Password to pass onto the ebay login
*
* @return string Current set password
*/
public function setPassword( $password ) {
return $this->password = $password;
}
/**
*
* Sets the filesystem path of the cookie that's stored
* @param string $cookie_path filesystem path to store cookie
*
* @return string Current set path
*/
public function setCookiePath( $cookie_path ) {
return $this->cookie_path = $cookie_path;
}
/**
*
* Uses getCurlResult function to login to eBay and create a cookie to use for further curl operations <br /> On successful login a "Page Not Responding" message will be displayed in the return HTML. <br /> On failure the login screen will be displayed again.
* @return string HTML output from the ebay login operation
*/
public function login() {
// 1-Get First Login Page http://signin.ebay.com/aw-cgi/eBayISAPI.dll?SignIn
// This page will set some cookies and we will use them for Posting in Form data.
$this->getCurlResult( $this->login_url );
// 2- Post Login Data to Page http://signin.ebay.com/aw-cgi/eBayISAPI.dll
$this->setReferer( "http://signin.ebay.com/aw-cgi/eBayISAPI.dll?SignIn" );
return $this->getCurlResult( $this->login_url, 'co_partnerId=2&pUserId='. $this->username .'&siteid=0&pageType=-1&pa1=&i1=-1&bshowgif=0&UsingSSL=0&ru=&pp=&pa2=&errmsg=8&runame=&ruparams=&ruproduct=&sid=&onepagereg=&sessid=&favoritenav=&confirm=&ebxPageType=&existingEmail=&isCheckout=&k=0&migrateVisitor=&searchname=&attributestring=&fstype=&fromwl=&pass='. $this->password );
// return will actually display a page from ebay mentioning there is no navigation, start from the homepage if login works.
// You will see an incorrect login message if it's broken
}
/**
*
* Sets the referer URL for cUrl calls.
* @param string $ref_url Referer URL
*/
public function setReferer( $ref_url ) {
$this->referer = $ref_url;
}
/**
*
* This function preforms the cURL call and returns the resulting HTML.
* @param string $url URL to request with cURL call
* @param string $post_fields post fields to be sent with cURL call [optional]
*
* @return string HTML from cURL call
*/
public function getCurlResult( $url, $post_fields = null ) {
$this->curl = curl_init();
curl_setopt( $this->curl, CURLOPT_URL, $url );
curl_setopt( $this->curl, CURLOPT_USERAGENT, $this->user_agent );
curl_setopt( $this->curl, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $this->curl, CURLOPT_FOLLOWLOCATION, 1 );
curl_setopt( $this->curl, CURLOPT_COOKIEFILE, $this->cookie_path );
curl_setopt( $this->curl, CURLOPT_COOKIEJAR, $this->cookie_path );
curl_setopt( $this->curl, CURLOPT_REFERER, $this->referer );
if( !is_null( $post_fields ) ) {
curl_setopt( $this->curl, CURLOPT_POST, 1);
curl_setopt( $this->curl, CURLOPT_POSTFIELDS, $post_fields );
}
$result = curl_exec( $this->curl );
curl_close( $this->curl );
return $result;
}
}
?>