2

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;
}
Waynn Lue
  • 11,344
  • 8
  • 51
  • 76
Jan
  • 42,290
  • 8
  • 54
  • 79
  • is it possible it's getting redirected? i know for the KDK site we had to do the same. – Waynn Lue Mar 08 '12 at 10:14
  • Hi Waynn, thanks four your answer. I'm using CURLOPT_FOLLOWLOCATION, additionally I haven't seen any Location-header in curl's verbose output (CURLOPT_VERBOSE). Did you guys manage to remotely login to KDK? – Jan Mar 08 '12 at 10:21
  • Yeah, though we're using rails and mechanize. I will say that we did have to turn off SSL verification for ours. – Waynn Lue Mar 08 '12 at 10:33
  • Analyzing the content, it says that my browser is too old. However, this->agent has the correct value (copied from $_SERVER). Very strange. – Jan Mar 08 '12 at 11:23
  • Aren't you missing the CURLOPT_COOKIEJAR option? – yann.kmm Mar 21 '12 at 17:57
  • I have tried but it didn't work either. – Jan Mar 21 '12 at 18:34

0 Answers0