I'm new here so hi to all community!
I need a little help with a 'simple' curl post connection.
here my test code, nothing special just init and exec a curl.
But the printed result variable contains the search form, not the result page, so i think there's some kind of cookie protection with a server side check/redirect.
please help me with this 🙂
$url = 'http://www.infoleges.it/Dogi2005/default.aspx';
$ch = curl_init();
$fields = array(
'orderby' => urlencode(1),
'MaxDocPagina' => urlencode(20),
'interodocumento' => urlencode(),
'PrimoElemento' => urlencode(),
'SecondoElemento' => urlencode(),
'Titolo' => urlencode(),
'Rivista' => urlencode(),
'idRivista' => urlencode(),
'AnnoPubblicazioneFrom' => urlencode(),
'AnnoPubblicazioneTo' => urlencode(),
'Fascicolo' => urlencode(),
'Tipologia' => urlencode(),
'tabtesti_testo' => urlencode(),
'Ambito' => urlencode(),
'Sezione' => urlencode(),
'NomeFonte' => urlencode(),
'Anno' => urlencode(2004),
'Mese' => urlencode(),
'Giorno' => urlencode(),
'Regione' => urlencode(),
'Citta' => urlencode(),
'Stato' => urlencode(),
'Numero' => urlencode(40),
'Articolo' => urlencode(),
'Fonte' => urlencode(),
'AreaGiuridica' => urlencode(),
'Classificazione' => urlencode(),
'doSearch' => urlencode("Cerca nell'archivio DoGi")
);
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.6 (KHTML, like Gecko) Chrome/16.0.897.0 Safari/535.6');
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
//execute post
$result = curl_exec($ch);
echo '<pre>';
$doc = new DOMDocument();
@$doc->loadHTML($result);
print_r($doc);
echo '</pre>';