Web crawler-How does PHP curl get verification code session_id?

Source: Internet
Author: User
Today trying to log in with curl, the verification code manually entered.

Questions and how do I use curl to simulate a form login with a picture verification code? Similar

And my question is how do I get the session or the settings when I pull the picture?

(The first answer to that question does not work correctly)

Ask the great God for answers.

Reply content:

Today trying to log in with curl, the verification code manually entered.

Questions and how do I use curl to simulate a form login with a picture verification code? Similar

And my question is how do I get the session or the settings when I pull the picture?

(The first answer to that question does not work correctly)

Ask the great God for answers.

$cookie_file = dirname(__FILE__).'/cookies/'.$user.'cookie.txt';// 初始化$curl = curl_init('http://');$header = array();$header[] = 'User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36';curl_setopt($curl, CURLOPT_HTTPHEADER, $header);// 不输出header头信息curl_setopt($curl, CURLOPT_HEADER, 0);// 保存到字符串而不是输出curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);curl_setopt($curl, CURLOPT_COOKIEJAR,  $cookie_file); //存储cookies// post数据curl_setopt($curl, CURLOPT_POST, 1);// 请求数据curl_setopt($curl, CURLOPT_POSTFIELDS, $post);// 是否抓取跳转后的页面curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);$response = curl_exec($curl);curl_close($curl);

Get session

Change it yourself, not universal. Togethers said no.

    //获取cookies值    private function getCookies(){        $curl = curl_init('http://113.57.132.2:83/login.aspx');        // 不输出header头信息        curl_setopt($curl, CURLOPT_HEADER, 1);        curl_setopt($curl, CURLOPT_NOBODY, 1);         // 伪装浏览器        curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36');        // 保存到字符串而不是输出        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);        $rs = curl_exec($curl);        curl_close($curl);        preg_match('%ASP.NET_SessionId=.*?;%sim',$rs,$arr);        $cookies=str_replace('ASP.NET_SessionId=','',$arr[0]);        $cookies=rtrim($cookies,';');        return $cookies;        //$this->$cookies=rtrim($cookies,';');    }
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.