Reputation: 65
I have simply script:
<?php if($_POST){
if($_POST['captcha'] == 'random'){ ?>
<div id="answer">
<?php echo $_POST['captcha'] . uniqid(); ?>
</div>
<?php
}
} ?>
<form name="contactform" method="post" action="">
email: <input type="text" name="email"> <br />
###IMAGE###: random <br />
captcha: <input type="text" name="captcha">
<input type="submit" value="Submit">
</form>
captcha is random, but for this test i use always 'random'. This script working OK.
So - i would like open this site and fill in captcha and submit form and receive data from DIV #answer.
I create:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://localhost/script.php');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$output = curl_exec($ch);
curl_close($ch);
print_r($output);
This show me form, but if i fill in captcha and submit form then this not handles $_POST.
How can i make it? I must first fill captcha.
Upvotes: 1
Views: 3253
Reputation: 7762
try this:-
$email = $_POST["email"];
$pass = $_POST["pass"];
$captcha = $_POST["captcha"];
$curlPost = array('email' => $email, 'password'=>'$pass', 'captcha'=>$captcha);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://localhost/script.php');
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
$data = curl_exec();
curl_close($ch);
echo "<pre>";
print_r($data);
Upvotes: 2
Reputation:
You forgot to send the data
$postdata = "email=".$username."&password=".$password."&captcha=random";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://localhost/script.php');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt ($ch, CURLOPT_POST, 1);
$output = curl_exec($ch);
curl_close($ch);
print_r($output);
Upvotes: 2