如何在不使用cURL重新加载页面的情况下发送数据?

时间:2017-05-27 16:32:34

标签: php curl post get

我正在尝试登录一个安全代码为2天的网站,如下所示。 enter image description here

(顺便说一句,我可以从网页的html代码中获取安全号码。)

首先,我必须连接到网站并获取代码(254),而不是发布用户名,密码和安全号码。但是有一个大问题。我收到安全号码,页面正在重新加载,每当我尝试将此变量发布到网页时,代码就会发生变化。

这是我的PHP代码:

<?php


    include('simple_html_dom.php'); 


    $url = "http://example.com/index.php";

    $useragent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36";

    $tmpfname = dirname(__FILE__).'/cookies.txt';

    $ch = curl_init();   // GET REQUEST
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_COOKIEJAR, $tmpfname);
        curl_setopt($ch, CURLOPT_REFERER, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
        $str = curl_exec($ch);
        echo $str; 
        curl_close($ch);

        preg_match('~<td><img src="number/(.*?).jpg"></td>~', $str, $securityNo); // I am gettin security number



    echo $securityNo[1]; // It print true

    $username = "USER";
    $password = "PASS";



    $postfields = array();
    $postfields['UserName'] =$username; // Username
    $postfields['Password'] = $password; // Password
    $postfields['code'] = $securityNo[1]; // Code
    $postfields['LOGIN'] = "LOGIN"; // BUTTON
    $curl =curl_init();

             curl_setopt($curl, CURLOPT_URL, $url);
             curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
             curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
             curl_setopt($curl, CURLOPT_REFERER, $url);
             curl_setopt($curl, CURLOPT_USERAGENT, $useragent);
             curl_setopt($curl, CURLOPT_POST, 1);
             curl_setopt($curl, CURLOPT_COOKIEFILE, $tmpfname);
             curl_setopt($curl, CURLOPT_POSTFIELDS, $postfields);
             curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); 
             curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);

        $ret = curl_exec($curl);
        curl_close($curl);
    echo $ret;

    ?>

我在屏幕上打印了'echo $ str'(获取请求)和'echo $ ret'(发布请求)但屏幕上有不同的2个代码,而不是打印相同的代码。

我在互联网上研究太多,但我一无所获。我无法解决这个问题。 提前谢谢!

0 个答案:

没有答案