How to retrieve captcha and save session with PHP cURL?(如何使用 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?)
这篇关于如何使用 PHP cURL 检索验证码并保存会话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 PHP cURL 检索验证码并保存会话?
基础教程推荐
- Libpuzzle 索引数百万张图片? 2022-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- 在多维数组中查找最大值 2021-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01