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,';'); }