我正在尝试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);
}
我正在尝试互联网上的几乎所有东西,但我无法管理任何事情。