I've been having a very frustrating problem with one of my CURL scripts lately. It's supposed to login to one of my affiliate programs and download the stats for me. The script was working fine until DirectTrack made some changes and went to HTTPS, now it's only partially working. Basically, I can get the script to login and navigate around some pages, but when it comes to downloading the actual stats file (which is a simple GET request), the whole process just hangs, and eventually returns a blank page.
Please let me know what other information I can give to help you. Here is my script:
$email_address = urlencode("xxx@xxxxxxxxx.com");
$password = "xxxxxxx";
$cookie_file_path = "cookie"; // cookie file (dont bother changing)
// 1 - Get the Cookies required to login from the welcome login page
$LOGINURL = "http://www.xxxxxx.com/";
$agent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$LOGINURL);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
$result = curl_exec ($ch);
curl_close ($ch);
// 2 - Post Login Cookies and Login Information to Page
$LOGINURL = "https://login.xxxxxx.com/login.html";
$reffer = "http://www.xxxxxx.com";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$LOGINURL);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "DL_AUTH_USERNAME=$email_address&DL_AUTH_PASSWORD=$password"); // add POST fields
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_REFERER, $reffer);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
$result = curl_exec ($ch);
curl_close ($ch);
Ok, the script works fine up to this point. When I print these results, I get the page displayed just as I should. However, when I go to download the stats file using the following code, it hangs:
// 4 - go to stats page
$LOGINURL = "https://login.xxxxxx.com/publishers/monthly_affiliate_stats.html?program_id=0&affiliate_stats_start_month=08&affiliate_stats_start_day=01...";
$reffer = "https://login.xxxxxx.com/partners/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$LOGINURL);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_REFERER, $reffer);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
$result = curl_exec ($ch);
curl_close ($ch);
print $result;
I've verified that I can login using Firefox and just copy and paste the above URL and the stats file downloads fine. I really don't know what to do here.
I should add, curl_error gives me this: "Connect failed; Operation now in progress", after about 5 minutes of waiting for the page to load.
Thanks!