更新:已解决
Hi all, i've got it, just save cookie to temp file, and resubmit form with curl and set cookies with previous temp file :) thanks all for respond :)
这是我的工作代码
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url_register);
curl_setopt($ch, CURLOPT_USERAGENT, $this->useragent);
curl_setopt($ch, CURLOPT_COOKIEJAR, $this->cookie);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$out['result'] = curl_exec($ch);
$out['error'] = curl_error($ch);
$out['info'] = curl_getinfo($ch);
curl_close($ch);
对于下一个 curl,只需像这样使用 CURLOPT_COOKIEFILE
/* fetch captcha url with existed cookie */
$ch = curl_init($captcha_url);
curl_setopt($ch, CURLOPT_USERAGENT, $this->useragent);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookie);
curl_setopt($ch, CURLOPT_FILE, $fp);
$out2['result'] = curl_exec($ch);
$out2['error'] = curl_error($ch);
$out2['info'] = curl_getinfo($ch);
curl_close($ch);
大家好,
我正在创建一些脚本以通过 php curl 提交内容。首先获取 session 和验证码,用户必须提交验证码才能最终提交。
问题是我无法获取验证码,我已经尝试使用此代码和 preg_match 来获取图像标签并将其返回
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2) Gecko/20070219 Firefox/2.0.0.2');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_COOKIE, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, "1");
curl_setopt($ch, CURLOPT_COOKIEFILE, "1");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$result = curl_exec($ch);
curl_close($ch);
但运气不好,我要提交的页面是 http://abadijayaiklan.co.cc/pasang-iklan/ .
我希望有人能帮助我:)
感谢和问候
最佳答案
在 curl_setopt
的 php 手册页中,CURLOPT_COOKIEFILE
和 CURLOPT_COOKIEJAR
都应该指定一个文件名。您将它们设置为“1”(这可能是有效的,但这是您想要的吗?)
关于php - 如何检索验证码并使用 PHP cURL 保存 session ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2527729/