1

我有简单的脚本:

<?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>

验证码是随机的,但对于这个测试,我总是使用“随机”。这个脚本工作正常。

所以 - 我想打开这个网站并填写验证码并提交表格并从 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。

我怎样才能做到?我必须先填写验证码。

4

2 回答 2

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);
于 2012-09-06T12:17:04.743 回答
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);
于 2012-09-06T12:18:41.863 回答