CURL PHP

Par glochen G Uyirr, il y a 9 ans


Bonjour,

j'utilise un code php curl pour récupérer un fichier sur un site.
il faut d'abord que je me connecte (donc récup de cookies de connexion)
puis ensuite, je récupère le fichier dans un output annonces.html

le problème est que je récupère le code html du formulaire de connexion à l'interface.

Pourtant, mon fichier de cookie est bien créé...

Je boucle..
Avez-vous une idée ?

Merci !

$timeout = 10; $alsa_username = '***'; $alsa_password = '****'; $cookies_file = 'files/cookies.txt'; /************************************************** Première requête : Connexion **************************************************/ $url = 'https://portail-partenaire.pole-emploi.fr/partenaire/remise'; $ch = curl_init($url); curl_setopt($ch, CURLOPT_FRESH_CONNECT, true); curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); if (preg_match('`^https://`i', $url)) { curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); } curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_NOBODY, true); // Forcer cURL à utiliser un nouveau cookie de session curl_setopt($ch, CURLOPT_COOKIESESSION, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, array( 'name' => $alsa_username, 'password' => $alsa_password, 'login-submit' => 'Connexion' )); // Fichier dans lequel cURL va écrire les cookies // (pour y stocker les cookies de session) curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies_file); curl_exec($ch); curl_close($ch); $source = "https://portail-partenaire.pole-emploi.fr/partenaire/remise?url=/ADODIFF?local_ident=683063"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $source); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSLVERSION,3); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $data = curl_exec ($ch); $error = curl_error($ch); echo $error; curl_close ($ch); $destination = "./files/annonces.html"; $file = fopen($destination, "w+"); fputs($file, $data); fclose($file);

1 réponse

glochen G Uyirr, il y a 9 ans

CA NE MARCHE JAMAIS !!!
mais j'ai trouvé comment faire !!!!
j'utilise la commande exec et je passe les commandes CURL !!