cURL / Mailing Lists / curl-library / Single Mail

curl-library

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

From: Ralph Mitchell <ralphmitchell_at_gmail.com>
Date: Wed, 9 May 2007 22:19:07 -0500

On 5/9/07, Znigniew Widomski <mazon26_at_yahoo.com> wrote:
> ------------------------------------------------------------------------------------------------------------------------
> 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?

I don't use curl with PHP, but it looks like one thing you don't
appear to be doing is sending the PHPSESSID that occurs in the page
source right alongside the form tag in a hidden input field. That
would help the server keep track of who it is talking to.

Ralph Mitchell
Received on 2007-05-10