Home > Backend Development > PHP Tutorial > Curl simulates password retrieval and an incomprehensible error occurs

Curl simulates password retrieval and an incomprehensible error occurs

WBOY
Release: 2016-08-08 09:06:38
Original
1198 people have browsed it

curl simulates password retrieval (Huaxia Insurance) and directly retrieves the password page http://www.ihxlife.com/forget...
Enter the mobile phone number 15677748704 (test) to get the verification code, it will directly prompt the verification code error
Curl simulates password retrieval and an incomprehensible error occurs
But First enter the official website and then enter the page through the official website link to get the verification code

Curl simulates password retrieval and an incomprehensible error occurs

Achieved through code. First visit the main page to get the cookie, then use the obtained cookie to visit the password retrieval page to update the cookie
Then get the verification code ——————Failed to send the SMS verification code failed

<code> public function forgetPwdIndex(){
        $uKey = 'HuaXia' . date("YmdHis") . uniqid();
        $cookieVerify = APP_COOKIE . "/" . $uKey . ".tmp";
        $url = 'http://www.ihxlife.com/';//登录主页的url来获取cookie
        $this->getCookie($url, $cookieVerify);//获取到登录页面的cookie
        //获取找回密码页的cookie
        $pwdUrl='http://www.ihxlife.com/forget/forgetPwd';
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $pwdUrl);
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:40.0) Gecko/20100101 Firefox/40.0');
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_TIMEOUT, 120); // 设置超时限制防止死循环
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
            'Accept-Encoding:gzip, deflate',
            'Accept-Language:zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
            'Connection:keep-alive',
            'Host:www.ihxlife.com'));
        curl_setopt($ch, CURLOPT_REFERER,'http://www.ihxlife.com/');
        curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieVerify);
        curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieVerify);
        curl_exec($ch);
        curl_close($ch);
        //echo $cookieVerify."<br>";
        $this->assign('key', $uKey);//传到页面中 在页面中post该数据 拼组cookie文件
        $this->display();
    }
    
    public function sendPwdMobileCode(){
    if(I('post.key')==''||I('post.mobile')==''){
        echo json_encode(array('status'=>'10001','message'=>'参数错误'));
        die;
    }
    $requireUrl='http://www.ihxlife.com/sms/smsCode_Send';//请求地址
    $postData='mobile='.I('post.mobile').'&busiType=10019&effectiveTime=180';
    $cookieVerify = APP_COOKIE . "/" . I('post.key') . ".tmp";
    echo $cookieVerify."<br>";
    $referer='http://www.ihxlife.com/forget/forgetPwd';
    echo $this->curlPost($requireUrl,$postData,$cookieVerify,$referer,30,true);
}
    
</code>
Copy after login
Copy after login
<code>       public function getCookie($url, $cookieVerify)
    {
        echo $cookieVerify."<br>";
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:40.0) Gecko/20100101 Firefox/40.0');
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
            'Accept-Encoding:gzip, deflate',
'Accept-Language:zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
'Connection:keep-alive',
'Host:www.ihxlife.com'));
        curl_setopt($ch, CURLOPT_TIMEOUT, 120); // 设置超时限制防止死循环
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieVerify);
        curl_exec($ch);
        curl_close($ch);
    }
    
    
 

public function curlPost($url, $post_fields, $cookieVerify, $referer = '', $timeOut = 30, $header = '')
{
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1);
    curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:40.0) Gecko/20100101 Firefox/40.0');
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
    if ($referer) {
        curl_setopt($curl, CURLOPT_REFERER, $referer);
    } else {
        curl_setopt($curl, CURLOPT_AUTOREFERER, 1);
    }
    if ($header) {
        //curl_setopt($curl, CURLOPT_HTTPHEADER, array('Host:www.ihxlife.com', 'X-Requested-With:XMLHttpRequest'));
        curl_setopt($curl, CURLOPT_HTTPHEADER, array('Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
            'Accept-Encoding:gzip, deflate',
            'Accept-Language:zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
            'Content-Type:application/x-www-form-urlencoded; charset=UTF-8',
            'Connection:keep-alive',
            'Host:www.ihxlife.com',
            'X-Requested-With:XMLHttpRequest'));
    }
    curl_setopt($curl, CURLOPT_POSTFIELDS, $post_fields);
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_COOKIEFILE, $cookieVerify);
    curl_setopt($curl, CURLOPT_COOKIEJAR, $cookieVerify);
    curl_setopt($curl, CURLOPT_TIMEOUT, $timeOut);
    curl_setopt($curl, CURLOPT_HEADER, 0);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $resultData = curl_exec($curl); // 执行操作
    curl_close($curl);
    return $resultData;
}</code>
Copy after login
Copy after login

Reply content:

curl simulates password retrieval (Huaxia Insurance) and directly retrieves the password page http://www.ihxlife.com/forget...
Enter the mobile phone number 15677748704 (test) to get the verification code, it will directly prompt the verification code error
Curl simulates password retrieval and an incomprehensible error occurs
But First enter the official website and then enter the page through the official website link to get the verification code

Curl simulates password retrieval and an incomprehensible error occurs

Achieved through code. First visit the main page to get the cookie, then use the obtained cookie to visit the password retrieval page to update the cookie
Then get the verification code ——————Failed to send the SMS verification code failed

<code> public function forgetPwdIndex(){
        $uKey = 'HuaXia' . date("YmdHis") . uniqid();
        $cookieVerify = APP_COOKIE . "/" . $uKey . ".tmp";
        $url = 'http://www.ihxlife.com/';//登录主页的url来获取cookie
        $this->getCookie($url, $cookieVerify);//获取到登录页面的cookie
        //获取找回密码页的cookie
        $pwdUrl='http://www.ihxlife.com/forget/forgetPwd';
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $pwdUrl);
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:40.0) Gecko/20100101 Firefox/40.0');
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_TIMEOUT, 120); // 设置超时限制防止死循环
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
            'Accept-Encoding:gzip, deflate',
            'Accept-Language:zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
            'Connection:keep-alive',
            'Host:www.ihxlife.com'));
        curl_setopt($ch, CURLOPT_REFERER,'http://www.ihxlife.com/');
        curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieVerify);
        curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieVerify);
        curl_exec($ch);
        curl_close($ch);
        //echo $cookieVerify."<br>";
        $this->assign('key', $uKey);//传到页面中 在页面中post该数据 拼组cookie文件
        $this->display();
    }
    
    public function sendPwdMobileCode(){
    if(I('post.key')==''||I('post.mobile')==''){
        echo json_encode(array('status'=>'10001','message'=>'参数错误'));
        die;
    }
    $requireUrl='http://www.ihxlife.com/sms/smsCode_Send';//请求地址
    $postData='mobile='.I('post.mobile').'&busiType=10019&effectiveTime=180';
    $cookieVerify = APP_COOKIE . "/" . I('post.key') . ".tmp";
    echo $cookieVerify."<br>";
    $referer='http://www.ihxlife.com/forget/forgetPwd';
    echo $this->curlPost($requireUrl,$postData,$cookieVerify,$referer,30,true);
}
    
</code>
Copy after login
Copy after login
<code>       public function getCookie($url, $cookieVerify)
    {
        echo $cookieVerify."<br>";
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:40.0) Gecko/20100101 Firefox/40.0');
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
            'Accept-Encoding:gzip, deflate',
'Accept-Language:zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
'Connection:keep-alive',
'Host:www.ihxlife.com'));
        curl_setopt($ch, CURLOPT_TIMEOUT, 120); // 设置超时限制防止死循环
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieVerify);
        curl_exec($ch);
        curl_close($ch);
    }
    
    
 

public function curlPost($url, $post_fields, $cookieVerify, $referer = '', $timeOut = 30, $header = '')
{
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1);
    curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:40.0) Gecko/20100101 Firefox/40.0');
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
    if ($referer) {
        curl_setopt($curl, CURLOPT_REFERER, $referer);
    } else {
        curl_setopt($curl, CURLOPT_AUTOREFERER, 1);
    }
    if ($header) {
        //curl_setopt($curl, CURLOPT_HTTPHEADER, array('Host:www.ihxlife.com', 'X-Requested-With:XMLHttpRequest'));
        curl_setopt($curl, CURLOPT_HTTPHEADER, array('Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
            'Accept-Encoding:gzip, deflate',
            'Accept-Language:zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
            'Content-Type:application/x-www-form-urlencoded; charset=UTF-8',
            'Connection:keep-alive',
            'Host:www.ihxlife.com',
            'X-Requested-With:XMLHttpRequest'));
    }
    curl_setopt($curl, CURLOPT_POSTFIELDS, $post_fields);
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_COOKIEFILE, $cookieVerify);
    curl_setopt($curl, CURLOPT_COOKIEJAR, $cookieVerify);
    curl_setopt($curl, CURLOPT_TIMEOUT, $timeOut);
    curl_setopt($curl, CURLOPT_HEADER, 0);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $resultData = curl_exec($curl); // 执行操作
    curl_close($curl);
    return $resultData;
}</code>
Copy after login
Copy after login

Problem solved. This website updated cookies when loading the verification code for the homepage login module. My previous thought was to load the page. I didn’t notice this. I just need to visit the homepage verification code again and save the updated verification code!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template