Comment afficher le contenu d'un URL(ici "http://www.somedomain.com/go.php" ) tout en envoyant un cookie enregistré dans un fichier(ici cookie.coo)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
<?php
 
//On enregistre le cookie recu dans cookie.coo apres envoie de données POST
$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.coo");
curl_setopt($ch, CURLOPT_URL,"http://www.somedomain.com/checkpwd.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "UserID=username&password=passwd");
 
ob_start();
curl_exec ($ch);
ob_end_clean();
 
curl_close ($ch);
unset($ch);
 
//Envoyer le cookie et aller à "http://www.somedomain.com/go.php"
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.coo");
curl_setopt($ch, CURLOPT_URL,"http://www.somedomain.com/go.php");
 
$buf2 = curl_exec ($ch);
 
curl_close ($ch);
//!!Est ce que le cookie est envoyé avec succée??
echo htmlentities($buf2);
//ÔÔ!! rien n'est affiché
?>