如何使用 PHP cURL 检索验证码并保存会话?
更新:已解决
大家好,我知道了,只需保存 cookie到临时文件,并重新提交表格卷曲并使用先前设置 cookie临时文件 :) 感谢大家的回复 :)
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
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);
大家好,
我正在创建一些脚本来通过 php curl 提交内容.首先获取会话和验证码,用户必须提交验证码才能最终提交.
i'm create some script to submit content via php curl. first fetch session and captcha, and user must submit captcha to final submit.
问题是我无法获取验证码,我已尝试使用此代码和 preg_match 获取图像标签并返回它
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);
但运气不好,我要提交的页面是 http://abadijayaiklan.co.cc/pasang-iklan/.
But no luck, page i'm trying to submit is http://abadijayaiklan.co.cc/pasang-iklan/.
希望有人能帮帮我:)
感谢和问候
推荐答案
从 curl_setopt
的 php 手册页,CURLOPT_COOKIEFILE
和 CURLOPT_COOKIEJAR
应该两者都指定一个文件名.您将它们设置为1"(这可能是有效的,但这是您想要的吗?)
From the php manual page on curl_setopt
, CURLOPT_COOKIEFILE
and CURLOPT_COOKIEJAR
should both specify a filename. You have them set to '1' (which may be valid, but is that what you intended?)
相关文章