PHP code to automatically bid/buy an eBay auction item

The following PHP code will automatically bid on an eBay item.

modify the following variables;

  • $username = “username”; //the eBay username
  • $password = “password”; //the eBay password
  • $item = 300712344201; //the item number
  • $bid =  0.01; //the  bid value in the item’s currency
<?php
	//modify the following

	$username = "username"; //the eBay username
	$password = "password"; //the eBay password

	$item = 300712344201; //the item number
	$bid =  0.01; //the  bid value in the item's currency

	//do not modify below

	//query the sign-in page
	$curl = curl_init();
	curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
	curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; rv:15.0) Gecko/20100101 Firefox/15.0.1");
	curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
	curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
	curl_setopt($curl, CURLOPT_COOKIEFILE, "cookies.txt");
	curl_setopt($curl, CURLOPT_COOKIEJAR, "cookies.txt");
	curl_setopt($curl, CURLOPT_URL,"http://signin.ebay.com/aw-cgi/eBayISAPI.dll?SignIn");
	$ret = curl_exec ($curl);
	curl_close ($curl);

	//sign-in
	$post = "MfcISAPICommand=SignInWelcome&siteid=0&co_partnerId=2&UsingSSL=0&ru=&pp=&pa1=&pa2=&pa3=&i1=-1&pageType=-1&userid={$username}&pass={$password}";

	$curl = curl_init();
	curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
	curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; rv:15.0) Gecko/20100101 Firefox/15.0.1");
	curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
	curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS,$post);
	curl_setopt($curl, CURLOPT_COOKIEFILE, "cookies.txt");
	curl_setopt($curl, CURLOPT_COOKIEJAR, "cookies.txt");
	curl_setopt($curl, CURLOPT_REFERER, "http://signin.ebay.com/aw-cgi/eBayISAPI.dll?SignIn");
	curl_setopt($curl, CURLOPT_URL, "http://signin.ebay.com/aw-cgi/eBayISAPI.dll");
	$ret = curl_exec ($curl);
	curl_close ($curl);

	if (strpos($ret, "Member id {$username}") === FALSE) {
		echo "Failed signing in.\r\n";
	} else {
		echo "Success signing in.\r\n";
	}

	//place the inital bid
	$url = "http://offer.ebay.com/ws/eBayISAPI.dll?MakeBid&item={$item}&maxbid={$bid}";

	$curl = curl_init();
	curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
	curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; rv:15.0) Gecko/20100101 Firefox/15.0.1");
	curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
	curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
	curl_setopt($curl, CURLOPT_COOKIEFILE, "cookies.txt");
	curl_setopt($curl, CURLOPT_COOKIEJAR, "cookies.txt");
	curl_setopt($curl, CURLOPT_URL, $url);
	$ret = curl_exec ($curl);
	curl_close ($curl);

	preg_match_all('/(?:value="([-0-9a-zA-Z]*)" *)?name="stok"(?: *value="([-0-9a-zA-Z]*)")?/', $ret, $regs);
	$stok = $regs[1][0];

	preg_match_all('/(?:value="([-0-9a-zA-Z]*)" *)?name="uiid"(?: *value="([-0-9a-zA-Z]*)")?/', $ret, $regs);
	$uiid = $regs[1][0];

	if (($stok) && ($uiid)) {
		echo "Success placing initial bid.\r\n";
	} else {
		echo "Failed placing initial bid.\r\n";
	}

	//confirm the bid
	$url = "http://offer.ebay.com/ws/eBayISAPI.dll?MfcISAPICommand=MakeBid&maxbid={$bid}&quant=1&mode=1&stok={$stok}&uiid={$uiid}&co_partnerid=2&user={$username}&fb=0&item={$item}";

	$curl = curl_init();
	curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
	curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; rv:15.0) Gecko/20100101 Firefox/15.0.1");
	curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
	curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
	curl_setopt($curl, CURLOPT_COOKIEFILE, "cookies.txt");
	curl_setopt($curl, CURLOPT_COOKIEJAR, "cookies.txt");
	curl_setopt($curl, CURLOPT_URL, $url);
	$ret = curl_exec ($curl);
	curl_close ($curl);

	if (strpos($ret, "you're the first bidder") === FALSE) {
		echo "Failed placing final bid.\r\n";
	} else {
		echo "Success placing final bid.\r\n";
	}

	//for testing
	//$fh = fopen("testhtml.html", 'w');
	//fwrite($fh, $ret);
	//fclose($fh);
?>

Posted

in

,

by

Comments

12 responses to “PHP code to automatically bid/buy an eBay auction item”

  1. xxx Avatar
    xxx

    Don’t work – Failed signing in. (

  2. jose Avatar
    jose

    does’t work do not sign in

    1. Travis h Avatar

      Make sure the cookies file is the absolute path on the server

      1. pepe Avatar
        pepe

        I caputered the $ret and an ebay message “Your web browser settings are blocking cookies.” appeas, my brower is not bloking anything, do you know why?

        1. Travis h Avatar

          @pepe, this means your cookie file is not working.
          is cookies.txt being updated on the server?

          1. pepe Avatar
            pepe

            yes every time that i run the script in the same directory there is the purchase.php file, is created a cookies.txt file

          2. Travis h Avatar

            sorry, to clarify,
            the cookies.txt file is being modified everytime yourun purchase.php?
            There is contents in the cookies.txt file?

          3. pepe Avatar
            pepe

            yes it changes, i see this because the time of the file change with every execution

          4. pepe Avatar
            pepe

            and the cookies file have a content

          5. Travis h Avatar

            pepe, really not sure what is going on.

            I have an updated bidding function that I have been using (more status checking). I will post that shortly, maybe that would work.

          6. pepe Avatar
            pepe

            ok thank you. please letme know

Leave a Reply

Your email address will not be published. Required fields are marked *