dongxuan2577 2019-01-31 13:39
浏览 83

使用带有Captcha的PHP中的file_get_contents进行POST

I want to read an external site after submit code with captcha. But using (PHP) file_get_contents the captcha is loaded 2 times, so its wrong.

The Form load an image to solve the captcha and sent via POST to the original site that show the result. Normally I solve the captcha and than, in the new site, I read (with my eyes) the content.

Now I want to let PHP read the content. I always solve first the captcha (in my page) and than send it to the other site and let (php) "file_get_contents" read the content.

HERE MY CODE..

<?php
    $captcha = $_POST["captcha"];
?>
<html>

<form method="post" action="(this page)">
<img src="remote-captcha"><input type="text" name="captcha">
<submit>

<?php
    $postdata = http_build_query(
        array(
        'captcha' => $captcha
        )
    );

    $opts = array('http' =>
        array(
            'method'  => 'POST',
            'header'  => 'Content-type: application/x-www-form-urlencoded',
            'content' => $postdata
        )
    );

    $context  = stream_context_create($opts);
    $result = file_get_contents('https://www.form-page', false, $context);
    $search = '/<div class="myclass">(.*)<\/div>/';
    preg_match($search, $result, $show);

echo $show[0];
?>

At this point the form is loaded 2 times so the captcha is wrong.

Can someone help me?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 delta降尺度方法,未来数据怎么降尺度
    • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
    • ¥15 再不同版本的系统上,TCP传输速度不一致
    • ¥15 高德地图点聚合中Marker的位置无法实时更新
    • ¥15 DIFY API Endpoint 问题。
    • ¥20 sub地址DHCP问题
    • ¥15 delta降尺度计算的一些细节,有偿
    • ¥15 Arduino红外遥控代码有问题
    • ¥15 数值计算离散正交多项式
    • ¥30 数值计算均差系数编程