Jump to content

Sign in to Amazon with PHP cURL


MacsRule

Recommended Posts

Hey all- first post; please don't bite  :P

 

I'm trying to sign in to Amazon with cURL, but coming up against cookie problems (presumably with their Javascript being silly). I'm just hoping for some pointers as to how to convince it that cookies are enabled and let me navigate around the site like a normal user.

 

Here's my code so far

 

$email = "[email protected]";
$password = "mypass";
$data = array(
"path" => "gp/yourstore",
"useRedirectOnSuccess" => "1",
"query" => "signIn=1",
"mode" => "",
"redirectProtocol" => "",
"pageAction" => "gp/yourstore",
"disableCorpSignUp" => "",
"action" => "sign-in",
"email" => $email,
"password" => $password
);

$cr = curl_init("https://www.amazon.co.uk/gp/flex/sign-in/select.html");
curl_setopt($cr, CURLOPT_RETURNTRANSFER, true);        // Get returned value as string (don’t put to screen)
curl_setopt($cr, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // Spoof the user-agent to be the browser that the user is on (and accessing the php script)
curl_setopt($cr, CURLOPT_COOKIEJAR, "cookie.txt");    // Use cookie.txt for STORING cookies
curl_setopt($cr, CURLOPT_POST, true); // Tell curl that we are posting data
curl_setopt($cr, CURLOPT_POSTFIELDS, $data); // Post the data in the array above
$output = curl_exec($cr); // Execute!
echo $output; // Spit out what we found
curl_close($cr); // Free the memory

$cr = curl_init("http://www.amazon.co.uk/gp/homepage.html");
curl_setopt($cr, CURLOPT_RETURNTRANSFER, true);        // Get returned value as string (don’t put to screen)
curl_setopt($cr, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // Spoof the user agent
curl_setopt($cr, CURLOPT_COOKIEFILE, "cookie.txt"); // Use cookie.txt for READING cookies
$output = curl_exec($cr);
curl_close($cr);
echo $output;

 

When I run it (with correct pass obv :D) I get an error asking me to enable cookies.

 

Please help, would appreciate hugely.

 

Thanks all!

Link to comment
https://forums.phpfreaks.com/topic/112458-sign-in-to-amazon-with-php-curl/
Share on other sites

Thanks for the reply

 

The file is fine, because a) it works with other sites b) it logs me in fine, but won't let me do anything, essentially (my name is in the header of the error page lol) and c) i just checked in case hehe

 

What's the best way to deduce what Amazon is doing to my cookies, and how can I emulate this with cURL?

 

Cheers

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.