aide sur l'utilisation du curl
Bonsoir tout le monde ,
je veut accéder avec php à une page qui nécessite une authentification et télécharger son code htlm ( fopen("http://exemple.com/id=2345") ) .
Avec curl j'ai réussis à faire l'authentification sur la page http://exeple.com/login.php et le fichier cookie.txt est créer et rempli mais après je trouve pas comment utiliser le cookie , après l'exécution de curl , j'ai fait un fopen mais je télécharge la page qui me dit que je doit être connecter pour voir la page ...
voici le code que j'ai écrit :
Code:
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 28 29 30 31
|
function login($lurl,$postfields)
{
$header_array[0] = "Keep-Alive: 300";
$header_array[1] = "Connection: Keep-Alive";
$header_array[2] = "Expect:";
$agent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$lurl);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_HEADER,0);
curl_setopt($ch, CURLOPT_HTTPHEADER,$header_array);
curl_setopt($ch, CURLOPT_USERAGENT,$agent);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$postfields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_COOKIEJAR,'cookie.txt');
$result= curl_exec($ch);
curl_close ($ch);
$hostfile = fopen("http://exemple.com/id=2345", 'r');
$fh = fopen("out.html", 'w');
while (!feof($hostfile)) {
$output = fread($hostfile, 8192);
fwrite($fh, $output);
}
fclose($hostfile);
fclose($fh); |
Merci beaucoup d'avance