如何使用 PHP cURL 检索验证码并保存会话?
更新:已解决
大家好,我已经知道了,只需保存 cookie 到临时文件,然后重新提交表单 卷曲并设置饼干与以前 临时文件:)感谢大家的回复:)
这是我的工作代码
$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);
大家好,
我正在创建一些脚本来通过phpcurl提交内容。首先获取会话和验证码,用户必须将验证码提交到最终提交。
问题是我无法获得验证码,我尝试使用此代码和 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/。
我希望有人能帮助我:)
谢谢和问候
UPDATE: SOLVED
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 :)
This my working code
$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);
And for next curl just use CURLOPT_COOKIEFILE like this
/* 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);
Hi all,
i'm create some script to submit content via php curl. first fetch session and captcha, and user must submit captcha to final submit.
the problem is i can't get captcha, i've try with this code and preg_match to get image tag and return it
$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);
But no luck, page i'm trying to submit is http://abadijayaiklan.co.cc/pasang-iklan/.
I hope someone can help me out :)
Thanks and regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从
curl_setopt
的 php 手册页来看,CURLOPT_COOKIEFILE
和CURLOPT_COOKIEJAR
都应该指定一个文件名。您将它们设置为“1”(这可能是有效的,但这是您想要的吗?)From the php manual page on
curl_setopt
,CURLOPT_COOKIEFILE
andCURLOPT_COOKIEJAR
should both specify a filename. You have them set to '1' (which may be valid, but is that what you intended?)