Sign In to Amazon using PHP script (CURL or Snoopy)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
MacsRule
Forum Newbie
Posts: 1
Joined: Mon Jun 30, 2008 5:35 am

Sign In to Amazon using PHP script (CURL or Snoopy)

Post by MacsRule »

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

Code: Select all

<?php
$email = "sample@email.com";
$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 :wink:) I get an error asking me to enable cookies. I imagine any solution will involve analysing data sent with live HTTP headers or something, but I don't have a clue what to do.

Please help, would appreciate hugely.

Thanks all!
Post Reply