Codice PHP:
<?php $url = "http://www.atb.bergamo.it/ITA/Default.aspx? SEZ=2&PAG=38&MOD=LINTRV"; $ckfile = tempnam ("/tmp", "CURLCOOKIE"); $ckfile = "C:\Prova\cookie.txt"; $ch = curl_init ();
curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_COOKIEJAR, $ckfile); curl_setopt($ch,CURLOPT_COOKIEFILE,$c kfile); curl_setopt($ch, CURLOPT_COOKIESESSION, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $html = curl_exec ($ch);
$viewstate = explode('id="__VIEWSTATE" value="', $html); $viewstate = explode('"', $viewstate[1]); $a = explode("/",$viewstate[0]); $viewstate = $a[1];
$sesid = explode('_SessionId', file_get_contents($ckfile)); $sesid = explode("\n", $sesid[1]); $sesid = trim($sesid[0]);
//echo "VIEWSTATE = ".$viewstate."
"; //echo "SESSIONE = ".$sesid."
";
$line=1; $direction = "A"; $a = "05/12/2012"; $date = explode("/",$a); $time = "05.00";
$post = "ScriptManager1=ctl13%24updPnlFermate %7Cctl13%24btnFilter&__EVENTTARGET=&_ _EVENTARGUMENT=&__LASTFOCUS=&__VIEWST ATE=%2F".$viewstate."&__SCROLLPOSITIO NX=0&__SCROLLPOSITIONY=0&txtSRC=&myTo olbar%24txtEMLDST=&myToolbar%24txtEML MIT=&myToolbar%24txtNTE=&ctl13%24drop LINE=".$line."&ctl13%24dropDir=".$dir ection."&ctl13%24txtDAY=".$date[0]."% 2F".$date[1]."%2F".$date[3]."&ctl13%2 4txtHOUR=".$time."&ctl13%24dropFermat e=-1&__ASYNCPOST=true&ctl13%24btnFilter= Filtra";
//$cookie = 'ASP.NET_SessionId='.$sesid.'; READONLY=MA==';
$httpHeader = array("User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:10.0.2) Gecko/20100101 Firefox/10.0.2", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accept-Language: it-it,it;q=0.8,en-us;q=0.5,en;q=0.3", "Accept-Encoding: gzip, deflate", "Connection: keep-alive", "X-MicrosoftAjax: Delta=true", "Cache-Control: no-cache, no-cache", "Content-Type: application/x-www-form-urlencoded; charset=utf-8", "Referer: [url]http://www.atb.bergamo.it/ITA/Default.aspx?[/url] SEZ=2&PAG=38&MOD=LINTRV", "Content-Length:".strlen($post));
//curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeader); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //curl_setopt($ch, CURLOPT_COOKIE, $cookie); curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$server_output = curl_exec ($ch);
curl_close ($ch);
die($server_output); ?>