cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: How to keep a cURL handle open, to post image verfication

From: Znigniew Widomski <mazon26_at_yahoo.com>
Date: Wed, 9 May 2007 19:43:03 -0700 (PDT)

original message and a reply by Dan:
  -------------------------------------------------------
  Message: 5
Date: Wed, 9 May 2007 12:18:49 -0700
From: Dan Fandrich <dan_at_coneharvesters.com>
Subject: Re: How to keep a cURL handle open, to post image verfication
 code
To: curl-library_at_cool.haxx.se
Message-ID: <20070509191848.GA23138_at_coneharvesters.com>
Content-Type: text/plain; charset=us-ascii
  On Wed, May 09, 2007 at 11:19:26AM -0700, Znigniew Widomski wrote:
> Hello I'm using the curl library in php. I'm trying to post to a form
with POST
  You might consider the PHP/CURL mailing list for such questions in the
future.
> but the form requires that a code be entered for image verification.
So
> basically what I need to do is first is load the form and grab the
contents
> from the form, and echo out the image for verification. Then I
physically type
> the code into a custom form of my own, and press submit. Then curl
will load
> the SAME surf session or form and submit to the form with the image
> verification code. The problem is normally when you make two
curl_init it loads
> the page twice, if I load the form twice there will be a different
image
> verfication code when I submit the code.
  Is your custom form sending to the correct post URL, or are you
attempting
to post to the HTML form page? You're probably missing some state
information
to connect the image to your response.
> I need to somehow keep the "surf session" open or handle or
something, so when
> I post to the form with the image verfication I read earlier, it will
be the
> same image verification code that it requires.
>
> Can anyone tell how this can be done wiht curl??
  libcurl does this by default on HTTP/1.1 servers. With the C binding,
you
simply reuse the easy handle without cleaning it between transfers.
But
that's not what you want here. HTTP is stateless (Microsoft
bastardizations
thereof excepted). The state which is needed by the server to connect
the
image it sent with your response is probably held in a hidden form or
in a
cookie. Try enabling libcurl's cookie handling and look for hidden
form
fields and try again.
>>> Dan

  ------------------------------------------------------------------------------------------------------------------------
  My reply to Dan and everyone else:
>>
  I show you what I am trying to do specifically with code:
  <?php
if (!isset($_GET['code'])) {
$formurl = 'http://p2mcity.freehostia.com/mh-db.php?add=problem';
 
$curlit = curl_init();
curl_setopt($curlit, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curlit, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curlit, CURLOPT_URL, $formurl);
$result = curl_exec($curlit);
$oneArray = explode('<td height="14"><input name="captcha" type="text" size="6" maxlength="5" />', $result);
$twoArray = explode('</td>', $oneArray[1]);
$image = $twoArray[0];
echo $image; //this echoes back the image for image verification from the html form
  echo '<form action="imagecurl.php" method="get" name="whatever">
Type in the code: <input name="code" type="text" size="6" maxlength="5" /><input type="submit" value="Submit"/></form>';
  } else {
$posturl = 'http://p2mcity.freehostia.com/mh-db.php';
$curlit = curl_init();
curl_setopt($curlit, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curlit, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curlit, CURLOPT_URL, $posturl);
curl_setopt ($curlit, CURLOPT_POSTFIELDS, "title=whatever&description=whatever&mhversion=123&nickname=whatever&email=whatever_at_whatever.com&livecontact=whatever&service=whatever&captcha=".$_GET['code']."&add=suggestion&Submit33=Submit");
$result = curl_exec($curlit);
echo $result;
  }
?>

  the html form resides here: 'http://p2mcity.freehostia.com/mh-db.php?add=problem'
  that is where I am trying to retrieve the image for image verification from
   
  the url where I am posting the data is here:
  'http://p2mcity.freehostia.com/mh-db.php
   
  As you can see in my code, I use curl to load the page twice, when I post to the form with the image code I retrieved and typed in, it is not correct because as each page load, (as it is custom with image verification) the code changes, and the image changes, I was trying to explain that I somehow need to retrieve the image, type the code, and post all in one page load, this is where I am stuck, the code I posted above shows "sorry you did not enter the wrong code" every SINGLE time, because of what i explained just earlier
   
  How can I do this with curl, to retrieve the image verification code, and then post the correct code to the form?
   
  -thank you

       
---------------------------------
Ahhh...imagining that irresistible "new car" smell?
 Check outnew cars at Yahoo! Autos.
Received on 2007-05-10