3

I need to login to Amazon page: https://sellercentral-japan.amazon.com/gp/sign-in/sign-in.html/ref=pt_login_lgin_login with PHP cURL (without Amazon Web Service).

Here is code how I tried for that:

const AMAZON_LOGIN_URL = "https://sellercentral-japan.amazon.com/gp/sign-in/sign-in.html/ref=pt_login_lgin_login";

$this->crawler = new crawler();        
// login with Amazon account
$parameters ='protocol=https&action=sign-in&email='.self::AMAZON_USER.'&password='.self::AMAZON_PWD;
$status = $this->crawler->logIn(self::AMAZON_LOGIN_URL, $parameters);

/* in crawler class */
//This is used for login.
function logIn($loginActionUrl, $parameters) {
    $strCookie = 'D:\public_html\project\cookie.txt';

    curl_setopt($this->curl, CURLOPT_URL, $loginActionUrl);
    curl_setopt($this->curl, CURLOPT_POST, 1);
    curl_setopt($this->curl, CURLOPT_POSTFIELDS, $parameters);

    curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($this->curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
    curl_setopt($this->curl, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($this->curl, CURLOPT_HEADER, 0);

    curl_setopt($this->curl, CURLOPT_COOKIEJAR, $strCookie);
    curl_setopt($this->curl, CURLOPT_COOKIEFILE, $strCookie);

    $content = curl_exec($this->curl);
    return $content;
}

As a response, I get login page with error message: "Your login session expired. Please sign in again." And this message is also displayed:

"Not Found

The requested URL /aan/2009-09-09/static/amazon/iframeproxy-12.html was not found on this server."

I have tried most of the solutions found on web. This solution was hopeful but still not working: PHP Curl - Cookies problem I have changed required login page URL and made few other changes but it give this error:

"There was an error trying to perform this operation. Please try again in 15 minutes." even after 15 min, it gives the same error.

If anybody can help, it would be help.

Thanks.

aynber
  • 22,380
  • 8
  • 50
  • 63
Kulin Choksi
  • 761
  • 1
  • 11
  • 30
  • I checked that page and you have to :1- request page and save cookies 2- send login data using cookies you got from previous request! – undone Jun 16 '12 at 07:16
  • Is that a class? Please show the other parts – Shiplu Mokaddim Jun 16 '12 at 08:14
  • @shiplu.mokadd.im: As you can see "logIn" function is not depended on other parts of class, you can consider it as independent procedure. – Kulin Choksi Jun 16 '12 at 09:03
  • @Death: Yes, I think we have used CURLOPT_COOKIEJAR and CURLOPT_COOKIEFILE for that purpose. Do you think, anything else is needed for that? Please elaborate. – Kulin Choksi Jun 16 '12 at 13:50
  • I know why you have used them, but for new login, you need new session data and you can't have those cookies unless you ask for new ones;-) – undone Jun 16 '12 at 13:54
  • 1
    And something else: you have to send **ALL** hidden inputs back to server (like `session-id`,`ouid`,`optin`,...) – undone Jun 16 '12 at 14:19
  • @Death: You are right, I checked again and some hidden fields were missing in postback. It's working now. Thanks a lot :-). If you can add your comment as an answer, I can accept it. – Kulin Choksi Jun 16 '12 at 15:09

2 Answers2

4

Just for marking as answer:
you have to 2 things:

  1. Request login page from server using get method
  2. Send login data using new session and with hidden inputs

to see the script : https://stackoverflow.com/a/7532730/889678

Community
  • 1
  • 1
undone
  • 7,857
  • 4
  • 44
  • 69
-2

Use their official Curl API... See php sample here http://login.amazon.com/website

giorgio79
  • 3,787
  • 9
  • 53
  • 85