I am working on a php script that can login to a webapp on a secure server and retrieve data via an export file.
I’ve managed to get the login to the server working (it’s using basic authentication which I’m adding to the url) and I arrive at the login page of the webapp. This requires me to POST the login details which I do. From what I’ve been able to determine so far by looking at the http is that:
- from the login page there is a redirect to a cookie_test page
- from here, the app should send a cookie
- then it redirects to the ‘home’ page of the webapp
what happens for me instead is that when I send the post data I get bounced back to the login page with a message that my browser is not setup to handle cookies. I’m stuck on how to debug this further as I’m not sure if the problem lies with how I’ve issued the POST, managed the cookies, or if it is some mistake I’ve made in setting up the test environment (I’m using xampp to run the script which accesses the outside secure server)
[php]
<?php
$headers = array(
"Authorization: Basic " . base64_encode("username:password"),
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"Accept-Language: en-us,en;q=0.5",
"Accept-Encoding: gzip,deflate",
"Connection: keep-alive",
"Content-Type: application/x-www-form-urlencoded",
);
$ch = curl_init("https://url");
$fp = fopen("page_info.txt", "w");
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, "return=redirect_url&username=usrname&password=passwrd");
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLINFO_HEADER_OUT, TRUE);
curl_setopt($ch, CURLOPT_UNRESTRICTED_AUTH, TRUE);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, FALSE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$chData = curl_exec($ch);
if(!curl_errno($ch)){
$info = curl_getinfo($ch);
echo 'Took ' . $info['request_header'] . ' seconds to send a request to ' . $info['url'];
} else {
echo 'Curl error: ' . curl_error($ch);
}
curl_close($ch);
echo $chData;
fclose($fp);
?>
[/php]
Any help on approaches I should be trying to debug this would be greatly appreciated.