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
Please help, would appreciate hugely.
Thanks all!