i'm trying to login to https://www.amzreviewtrader.com/ (thanks to https://www.amzreviewtrader.com/account.php page). I noticed that there is always a token whick will change every refresh. So with first curl i get it. After, i try to pass token, email and password with post method. but i can't login, i don't know why.
function grab_page($site){
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_TIMEOUT, 40);
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch, CURLOPT_URL, $site);
ob_start();
return curl_exec ($ch);
ob_end_clean();
curl_close ($ch);
}
function login($url){
$get_token = curl_init($url);
curl_setopt($get_token, CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($get_token, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($get_token, CURLOPT_TIMEOUT, 40000);
curl_setopt($get_token, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($get_token, CURLOPT_URL, $url);
curl_setopt($get_token, CURLOPT_FOLLOWLOCATION, TRUE);
$response = curl_exec($get_token);
$html = str_get_html($response);
$token = $html->find('div.col-xs-12 form.form-horizontal input')[0]->value;
echo $token;
$login = curl_init($url);
curl_setopt($login, CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($login, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($login, CURLOPT_TIMEOUT, 40000);
curl_setopt($login, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($login, CURLOPT_URL, $url);
curl_setopt($login, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($login, CURLOPT_POST, TRUE);
curl_setopt($login, CURLOPT_POSTFIELDS, "account_token=".$token."&email=xxxxxxxxx@xxxxx.xx&password=xxxxxxx");
return curl_exec ();
curl_close ();
grab_page("https://www.amzreviewtrader.com/product-list.php");
}