cURL / Mailing Lists / curl-and-php / Single Mail

curl-and-php

CURL and cookies

From: Amaury Willemant <awillemant_at_yahoo.fr>
Date: Tue, 30 May 2006 08:22:40 +0000 (GMT)

!-- DIV {margin:0px;}-->Thanks for your answer, maybe my problem does not come from the cookies.

So I will show you my code in PHP:
======================

//GET FORM INFORMATIONS
$ch = curl_init();
$adresse='https://intrapril.april.fr';
curl_setopt($ch, CURLOPT_USERAGENT,$_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt ($ch, CURLOPT_URL,$adresse);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$cookie='cookie.txt';
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,0);
$form=curl_exec ($ch);

//GET ACTION ATTRIBUTE FROM THE FORM
$regex="!action=\ "(.*)\ "!isU";
$res=array();
preg_match_all($regex,$form,$res);
$action=$res[1][0];

//GET __VIEWSTATE HIDDEN VARIABLE
$regex="!name=\ "__VIEWSTATE\ " value=\ "(.*)\ "!isU";
$res=array();
preg_match_all($regex,$form,$res);
$viewstate=$res[1][0];

$tabaction=explode("?",$action);
$adresse="https://intrapril.april.fr/IntraprilV2/UIL/Web/Partage/Cms/".$tabaction[0]."?".str_replace("&","&",$tabaction[1]);

$postfields="__EVENTTARGET=".
            "&__EVENTARGUMENT=".
            "&__VIEWSTATE=".urlencode($viewstate).
             "&Login1:noCorrespondant=".urlencode("<my_login>").
            "&Login1:MotDePasse=".urlencode("<my_code>").
            "&Login1:Connexion_x=10".
            "&Login1:Connexion_y=10";

curl_setopt($ch, CURLOPT_URL,$adresse);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,0);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$postfields);

curl_exec ($ch);

curl_close($ch);

AND THE GENERATED HTML
==================

<form name="Login1:Form1" method="post" action="<? echo $adresse; ?>" id="Login1_Form1">
<input type="hidden" name="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" value="<? echo $viewstate ;?>" />
<input name="Login1:noCorrespondant" id="Login1_noCorrespondant" type="text" class="textbox" /><br>
<input name="Login1:MotDePasse" id="Login1_MotDePasse" type="password" class="textbox" /><br>
<input id="Checkbox" type="checkbox" value="checkbox" name="checkbox" class="checkbox">

</form>

$_GET & $_POST are exactly the same in the two cases (I tested it with WinMerge) but only the HTML FORM works when I submit it. That's why I thought it was a cookie problem. If it is not a cookie problem, how the website "https://intrapril.april.fr" can do to reject me in the curl case ?

Thank you in advance !

Amaury

 

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2006-05-30