How to retrieve captcha and save session with PHP cURL?

不想你离开。 提交于 2019-11-28 05:55:00

问题


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


回答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?)



来源:https://stackoverflow.com/questions/2527729/how-to-retrieve-captcha-and-save-session-with-php-curl

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!