I'm trying to do a login in a Esse3 Platform with Curl PHP. Here the snippet:
<?
function get_jsessionid($url){
$ch = curl_init($url);
print_r($ch);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
$result=curl_exec ($ch);
preg_match_all('/^Set-Cookie:\s*([^;]*)/mi', $result, $matches);
$cookies = array();
foreach($matches[1] as $item) {
parse_str($item, $cookie);
$cookies = array_merge($cookies, $cookie);
}
return $cookies['JSESSIONID'];
}
$username='';
$password='';
$baseurl='https://webstudenti.unica.it/esse3/Home.do';
$loginurl= 'https://webstudenti.unica.it/esse3/auth/Logon.do;jsessionid=' . get_jsessionid($baseurl);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$loginurl);
curl_setopt($ch, CURLOPT_TIMEOUT, 30); //timeout after 30 seconds
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); //get status code
$result=curl_exec ($ch);
curl_close ($ch);
print_r($result);
Obviously now I've deleted my credentials, but the code doesn't work. I've tried a lot of time with differents snippet but login doesn't go. Do you have any solution? Ps: code works, but the remote webapp give me a login error.