有验证码的CURL网页?

时间:2017-02-20 19:48:51

标签: php session curl cookies captcha

我正在尝试cURL一个有验证码的网页然后我收到图像并将其显示给用户然后提交但我收到会话过期错误。甚至没有错误的验证码错误。

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 10.0; WOW64; rv:45.0)     Gecko/20100101 Firefox/45.0"); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

preg_match_all('/^Set-Cookie:\s*([^;]*)/mi', $result, $matches);
$cookies = array();
foreach($matches[1] as $item) {
parse_str($item, $cookie);
$cookies = array_merge($cookies, $cookie);
}

然后,如果提交了代码;

if(isset($_POST['submit'])) {
curl_setopt($ch, CURLOPT_URL, $url1); 
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $postinfo); 
foreach($cookies as $key => $val) {
curl_setopt($ch, CURLOPT_COOKIE, $key.'='.$cookie);
}

我正在尝试互联网上的几乎所有东西,但我无法管理任何事情。

0 个答案:

没有答案