I'd like to automate the summaries from KDP (Kindle Desktop Publishing). As they don't seem to have any email notification system (at least none that I'm aware of), I need to login via curl. It drives me nuts though. I'm using simplehtmldom to retrieve the hidden input values of their login site. The cookies are correct, as are the credentials. Is there something I'm completely missing? $response always gives me the original login site. Consider the following code:
function login($url) {
require_once(dirname(__FILE__).'/simplehtmldom/simple_html_dom.php');
$html = file_get_html($url);
$formarr = array();
$form = $html->find('#ap_signin_form',0);
$formarr["email"] = $this->user;
$formarr["password"] = $this->pass;
foreach ($html->find('#ap_signin_form input[type=hidden]') as $i)
$formarr[$i->name] = $i->value;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $form->action );
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $formarr);
curl_setopt($ch, CURLOPT_USERAGENT, $this->agent);
curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookie);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt($ch, CURLOPT_AUTOREFERER, true );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false ); # required for https urls
$response = curl_exec($ch);
return $response;
}