如何检索验证码和保存会话与PHP cURL? [英] How to retrieve captcha and save session with PHP cURL?

查看:129
本文介绍了如何检索验证码和保存会话与PHP cURL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

UPDATE:SOLVED

UPDATE: SOLVED


您好,我有它,只需将cookie
保存到temp文件,然后重新提交感谢所有回应:)

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 b
$ b

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 get image tag and return it

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/.

我希望有人可以帮助我:)

I hope someone can help me out :)

感谢和关心

推荐答案

curl_setopt 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆