Here is the code that I have been using in order to write a script that logs into my university website in order to pull a file from behind the login.
What consistently happens is that it returns the login page (remembering my username in this form) but it does not authenticate. I have a feeling that the password isn't being transferred, but I don't know why. I've tried looking at the post requests that get sent through my browser when I do it manually, and everything looks fine. Fields should be username and password respectively...
<?php
$username = 'someuser';
$password = 'somepass';
$loginUrl = 'https://vault.andrews.edu/vault/goto/login';
$loginFields = array('username'=>$username, 'password'=>$password); //login form field names and values
$remotePageUrl = 'google.com'; // Will be changed to a remote page
$login = getUrl($loginUrl, 'post', $loginFields); //login to the site
$remotePage = getUrl($remotePageUrl); //get the remote page
function getUrl($url, $method='', $vars='') {
$ch = curl_init();
if ($method == 'post') {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);
}
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
//curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/600.7.12 (KHTML, like Gecko) Version/8.0.7 Safari/600.7.12");
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies/cookies.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies/cookies.txt');
$buffer = curl_exec($ch);
print $buffer;
curl_close($ch);
return $buffer;
}
print $login;
?>
Can anybody figure out why it's not going through? I'm sorry that I cannot share real credentials for you all to use.