MacsRule Posted June 29, 2008 Share Posted June 29, 2008 Hey all- first post; please don't bite 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 ) 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 More sharing options...
thatsgreat2345 Posted June 29, 2008 Share Posted June 29, 2008 Are you sure cookie.txt has a chmod to allow being written to? Link to comment https://forums.phpfreaks.com/topic/112458-sign-in-to-amazon-with-php-curl/#findComment-577427 Share on other sites More sharing options...
MacsRule Posted June 29, 2008 Author Share Posted June 29, 2008 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 Link to comment https://forums.phpfreaks.com/topic/112458-sign-in-to-amazon-with-php-curl/#findComment-577433 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.