I am trying to grab my amazon associates stats automatically via cUrl. However I am falling down at the first hurdle; logging in.
When I use the following code:
You need to get amazon to set the cookie first.
Try:
// 1. Create a cookie file and set basic params
$ckfile = tempnam ("/your/path/to/cookie/folder", "cookie.txt");
$target_host = "https://affiliate-program.amazon.com";
$target_request = "/gp/flex/sign-in/select.html";
$post_data = "action=sign-in&email=$username&password=$password";
// 2. Visit homepage to set cookie
$ch = curl_init ($target_host);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $ckfile);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec ($ch);
// 3. Continue
$login = curl_init ($target_host.$target_request);
curl_setopt($login, CURLOPT_COOKIESESSION, 1);
curl_setopt($login, CURLOPT_COOKIEJAR, $ckfile);
curl_setopt($login, CURLOPT_COOKIEFILE, $ckfile);
curl_setopt($login, CURLOPT_TIMEOUT, 40);
curl_setopt($login, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($login, CURLOPT_HEADER, 1);
curl_setopt($login, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($login, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($login, CURLOPT_POST, 1);
curl_setopt($login, CURLOPT_POSTFIELDS, $post_data);
echo curl_exec($login);
curl_close($login);