views:

35

answers:

0

Hi,

I'm trying to login to a remote site called Lectio. The site sets six cookies on your computer when you visit it. When I try to log in with cURL, I only get two cookies.

Three of these six cookies should be set even when entering the site and not logging in. I get two of these cookies. I guess the last one is set through JavaScript and therefore, I wanna send it manually. This cookie is called 'loggedin3' and it will be equally to 'N' when not logged in and 'Y' when logged in. So I'm sending it 'loggedin3=N'.

I'm now trying to post my username and password. This should get me the last cookies - but it doesn't! In cookie.txt I only get the cookies which are set without logging in.

Then I make a second cURL connection which goes to the subpage and tries to receive it's source. It should get the cookies stored in 'cookie.txt', send 'loggedin3=Y' and print out the source.

This is my code:

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, 'https://www.lectio.dk/lectio/285/login.aspx');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIE, 'isloggedin3=N');
curl_setopt($ch, CURLOPT_POSTFIELDS, 'm$Content$username2=**REMOVED**&m$Content$password2=**REMOVED**');
curl_setopt($ch, CURLOPT_COOKIEFILE, realpath("cookie.txt"));
curl_setopt($ch, CURLOPT_COOKIEJAR, realpath("cookie.txt"));
curl_exec($ch); 
curl_close($ch);

$ch2 = curl_init(); 
curl_setopt($ch2, CURLOPT_URL, 'http://www.lectio.dk/lectio/285/SkemaNy.aspx?type=elev&elevid=1628118635');
curl_setopt($ch2, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch2, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch2, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch2, CURLOPT_COOKIE, 'isloggedin3=Y');
curl_setopt($ch2, CURLOPT_COOKIEFILE, realpath("cookie.txt"));
curl_setopt($ch2, CURLOPT_COOKIEJAR, realpath("cookie.txt"));
$output = curl_exec($ch2);
curl_close($ch2); 
print $output;

Simply, the cookies are not set after a log in. It seems the log in does not work.

Does anyone have any ideas?