I'm trying to make a PHP script which should login to a remote site the go to a subpage and get the source of this page.
The purpose is to retrive an image. This task shall be repeated for every student on my school (though I do believe it will only be necessary to login once, then go to the subpages).
My problem is, that I cannot get the script to login. I have not tried retrieving any images yet, since the first step must be to have the login process working.
I hope there's somebody out there who can help me login to this site and retrieve the source.
I'm trying to login to this form ('brugernavn' is username in Danish, 'adgangskode' is password):
https://www.lectio.d.../285/login.aspx
This is my code:
$curl_connection = curl_init('https://www.lectio.dk/lectio/285/login.aspx'); // establish connection
// cURL options
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30); // timeout 30 sec
curl_setopt($curl_connection, CURLOPT_USERAGENT,'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)'); // simulated browser
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true); // force cURL to not display the output but return as a string
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false); // does not trigger error when no SSL certificate
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1); // follow directions from remote sites header
curl_setopt($curl_connection, CURLOPT_COOKIEJAR, 'cookie.txt'); // save cookie in cookie.txt
// data to submit to remote form
$post_data['m$Content$username2'] = ''; //username removed
$post_data['m$Content$password2'] = ''; // password removed
// format data to string (eg. key1=value1&key2=value2)
foreach ($post_data as $key => $value) {
$post_items[] = $key . '=' . $value;
}
$post_string = implode ('&', $post_items);
// cURL options
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string); // post $post_string
print_r(curl_getinfo($curl_connection)); // print error check
echo '<hr />'.curl_errno($curl_connection).'-'.curl_error($curl_connection); // print error numbers
$result = curl_exec($curl_connection); // execute
curl_close($curl_connection); // close connection
// go to other page
$curl_connection = curl_init();
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_connection, CURLOPT_COOKIEFILE, 'cookie.txt');
curl_setopt($curl_connection, CURLOPT_URL, 'https://www.lectio.dk/lectio/285/SkemaNy.aspx?type=elev&elevid=1628118635');
$result = curl_exec($curl_connection); // execute
curl_close ($curl_connection); // close connection
echo $result; // print source
I have made a file called 'cookie.txt' in the same folder as the script is in and given it the permissions 777.
This is the output of the above code ('log ind' means 'log in' in Danish - therefore the script has obviously not logged in):
Eleven Simon Binderup Støvring, 3z - Skema - Lectio - Mariagerfjord Gymnasium
I hope somebody can help me :-)
Thanks in advance,
Simon B. Støvring


Sign In
Create Account

Back to top









