Hej,
Med hjælp fra Casper, er det lykkedes mig at komme lidt nærmere et færdigt resultat. Scriptet virker dog ikke helt endnu - den er stadig ikke logget ind, men jeg tror, at dette skyldes, at scriptet kun gemmer to ud af seks cookies i cookie.txt. Logger jeg ind via min browser, gemmes der seks cookies på computeren, men scriptet gemmer altså kun seks.
Er der nogen, der har et bud på, hvorfor scriptet ikke gemmer alle? Eller om det er et andet sted, der er noget i vejen?
$curl_connection = curl_init(); // establish connection
// cURL options
curl_setopt($curl_connection, CURLOPT_URL, '
https://www.lectio.dk/lectio/285/login.aspx');
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false); // does not trigger error when no SSL certificate
curl_setopt($curl_connection, CURLOPT_POST, 1);
// data to submit to remote form
$post_data['m$Content$username2'] = '2008zsbs'; //username removed
$post_data['m$Content$password2'] = 'medion1113'; // 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
curl_setopt($curl_connection, CURLOPT_COOKIEFILE, realpath('cookie.txt')); // save cookie in cookie.txt
curl_setopt($curl_connection, CURLOPT_COOKIEJAR, realpath('cookie.txt')); // save cookie in cookie.txt
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, true); // follow directions from remote sites header
curl_setopt($curl_connection, CURLOPT_HEADER, true);
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_exec($curl_connection);
curl_close($curl_connection);
// 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_URL, '
https://www.lectio.dk/lectio/285/SkemaNy.aspx?type=elev&elevid=1628118635');
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false); // does not trigger error when no SSL certificate
curl_setopt($curl_connection, CURLOPT_COOKIEFILE, realpath('cookie.txt'));
curl_setopt($curl_connection, CURLOPT_COOKIEJAR, realpath('cookie.txt'));
curl_setopt($curl_connection, CURLOPT_HEADER, true);
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_FOLLOWLOCATION, 1); // follow directions from remote sites header
$result = curl_exec($curl_connection); // execute
curl_close($curl_connection); // close connection
echo $result; // print source