"; } } // se la cache non c'e' oppure e' scaduta: if ($output == "") { $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_NOBODY, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_MAXREDIRS, 10); //follow up to 10 redirections - avoids loops $data = curl_exec($ch); curl_close($ch); preg_match_all("/HTTP\/1\.[1|0]\s(\d{3})/",$data,$matches); $code = end($matches[1]); $codeclass = $code{0}; if(!$data) { } else { if(($codeclass==2)or($codeclass==3)) { $ch2 = curl_init(); $timeout = 2; // set to zero for no timeout curl_setopt ($ch2, CURLOPT_URL, $url); curl_setopt ($ch2, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch2, CURLOPT_CONNECTTIMEOUT, $timeout); $output = curl_exec($ch2); $file =fopen($filename, "w"); fwrite($file,$output . ""); fclose($filename); curl_close($ch2); } elseif(($codeclass==4)or($codeclass==5)) { /*$file_contents = "Animali senza casa.org, il portale delle adozioni gratuite di cani e gatti."; */ $output = file_get_contents($filename) ; } } } // display file echo $output; ?>