0) { foreach($curl_data as $key=>$value) { $fields .= $key.'='.$value.'&'; } rtrim($fields,'&'); $post = true; } $options = array( CURLOPT_RETURNTRANSFER => true, // return web page CURLOPT_HEADER => false, // don't return headers CURLOPT_FOLLOWLOCATION => true, // follow redirects CURLOPT_ENCODING => "", // handle all encodings CURLOPT_USERAGENT => $user_agent, // who am i CURLOPT_AUTOREFERER => true, // set referer on redirect CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect CURLOPT_TIMEOUT => 120, // timeout on response CURLOPT_MAXREDIRS => 10, // stop after 10 redirects CURLOPT_POST => $post, // i am sending post data CURLOPT_POSTFIELDS => $fields, // this are my post vars CURLOPT_SSL_VERIFYHOST => 0, // don't verify ssl CURLOPT_SSL_VERIFYPEER => false, // CURLOPT_VERBOSE => $verbose , // //CURLOPT_COOKIESESSION => true, CURLOPT_COOKIEFILE => $ckfile, CURLOPT_COOKIEJAR => $ckfile, // Stockage du cookie de session ); $ch = curl_init($url); curl_setopt_array($ch,$options); $content = curl_exec($ch); $err = curl_errno($ch); $errmsg = curl_error($ch) ; $header = curl_getinfo($ch); curl_close($ch); // $header['errno'] = $err; // $header['errmsg'] = $errmsg; // $header['content'] = $content; return array('header'=>$header, 'content'=>$content); } //==> Start $debug = false; $config = parse_ini_file(dirname(__FILE__).'/../application/configs/configuration.ini', true); $directory = $config['path']['data'].'/bodacc'; //Ajout du type de bodacc $directory.= '/'.$type; if ( !file_exists($directory) ) mkdir($directory); //Ajout de l'annee $directory.= '/'.$annee; if ( !file_exists($directory) ) mkdir($directory); //Define cookie file for storage $ckfile = dirname(__FILE__).'/'.uniqid('cookies-'); echo $url = "http://www.bodacc.fr/index.php?action=voir&p=$type&n=$annee$num&a=$annonce"; echo "\n"; $result = getPage($url); if ($debug) file_put_contents('bodacc1.html', $result['content']); preg_match('/\/', $result['content'], $matches); echo $url = "http://www.bodacc.fr/index.php?action=pdf&index=".$matches[1]; echo "\n"; $result = getPage($url); if (substr($result['content'],0,4)!='%PDF'){ if ($debug) file_put_contents('bodacc2.html', $result['content']); echo "Erreur téléchargement du PDF."; echo "\n"; exit; } file_put_contents($directory."/BODACC_".$type."_".$annee."_".$num.".pdf", $result['content']); echo "\n"; if (file_exists($ckfile)) unlink($ckfile);