我只是脚本:
<?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是随机的,但对于这个测试,我总是使用“随机”。这个脚本运行正常。
所以 - 我想打开这个网站并填写验证码并提交表格并从DIV #answer接收数据。
我创建:
$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);
这显示我的表格,但如果我填写验证码并提交表格,那么这不会处理$ _POST。
我怎么做到的?我必须先填写验证码。
答案 0 :(得分:2)
您忘记发送数据
$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);
答案 1 :(得分:2)
试试这个: -
$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);