How to log in to Amazon using CURL PHP?

've written a function to log on to Amazon (need for some action to authenticate)

function amazon_authorization($email,$password){
 $cookie_file='/var/www/html/cookies/'.md5(date("Y-m-d H:i:s")).'.txt';
 $fp=fopen($cookie_file,'w'); fclose($fp);
$url='https://www.amazon.co.uk/ap/signin?_encoding=UTF8';
$url.='&ignoreAuthState=1';
$url.='&openid.assoc_handle=gbflex';
$url.='&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select';
$url.='&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select';
$url.='&openid.mode=checkid_setup';
$url.='&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.ns.pape=http%3A%2F%2Fspecs.openid.net%2Fextensions%2Fpape%2F1.0';
$url.='&openid.pape.max_auth_age=0';
$url.='&openid.return_to=https%3A%2F%2Fwww.amazon.co.uk%2F%3Fref_%3Dnav_signin';
$url.='&switch_account=';
 # go to the login page
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_COOKIEJAR,$cookie_file);
curl_setopt($ch,CURLOPT_COOKIEFILE,$cookie_file);
curl_setopt($ch,THIS,FALSE);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,FALSE);
 curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:35.0) Gecko/20100101 Firefox/35.0');
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,TRUE);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);
$content=curl_exec($ch);
 # Get the hidden fields
$url_referer=$url;
 if(!preg_match('/<form name="signIn".*?<\/form>/is',$content,$form)) die('Failed to find log in form!');
$form=$form[0];
 if(!preg_match('/action=(?:\'|")?([^\s\'">]+)/i',$form,$act)) die('Failed to find login form url');
$url=$act[1];
 $c=preg_match_all('/<input type="hidden"\s*name="([^"]*)"\s*value="([^"]*)"/i',$form,$hiddenFields);
$postFields=array();
 for($i=0; $i<$c; ++$i){ $postFields[$hiddenFields[1][$i]] = $hiddenFields[2][$i]; }
 # add your password and login
$postFields['email']=$email;
$postFields['password']=$password;
$post=";
 foreach($postFields as $key=>$value){ $post.=$key.'='.urlencode($value).'&'; }
$post=substr($post,0,-1);
 # authorization
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_REFERER,$url_referer);
curl_setopt($ch,CURLOPT_POST,TRUE);
curl_setopt($ch,CURLOPT_POSTFIELDS,$post);
$content=curl_exec($ch);
curl_close($ch);

 echo $content;

unlink($cookie_file);
 return true;
 }

Summary - generates a captcha

Important Message!
To better protect your account, please re-enter your password and then enter the characters as they are shown in the image below.

Checked all the hidden fields are the same, like all right, but always captcha...

Tell me something I can do?
March 20th 20 at 11:53
1 answer
March 20th 20 at 11:55
Amazon so do not be fooled. Use the API
for some reason API can't use, that's trying to imitate... - daphney54 commented on March 20th 20 at 11:58
@darlene.Nicolas, 95% chance of failure - carolanne.Weissn commented on March 20th 20 at 12:01
no anti-bot protection doesn't pass the Turing test, do not invent. - opal_Wisoz commented on March 20th 20 at 12:04
@karianne_Greenfelder12, there is a very good all security. Especially from such simple scripts - carolanne.Weissn commented on March 20th 20 at 12:07

Find more questions by tags PHPAmazon