1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| $url = 'http://www.monsite.net';
$user_agent = 'Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1'; // simule Firefox 4.
$header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,";
$header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
$header[] = "Cache-Control: max-age=0";
$header[] = "Connection: keep-alive";
$header[] = "Keep-Alive: 300";
$header[] = "Accept-Charset: utf-8";
$header[] = "Accept-Language: fr"; // langue fr.
$header[] = "Pragma: "; // Simule un navigateur
$ch = curl_init(); // initialize curl
curl_setopt($ch, CURLOPT_URL, $url); // l'url visité
curl_setopt($ch, CURLOPT_FAILONERROR, 1);// Gestion d'erreur
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // autorise la redirection
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // stock la response dans une variable
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_PORT, 80); // set port 80
curl_setopt($ch, CURLOPT_TIMEOUT, 15); // timeout curl à 15 secondes.
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
$return = curl_exec($ch); // stock les données dans la variable $return
$statut = @curl_getinfo($ch);
print_r($statut);
print_r($return);
curl_close($ch); |
Partager