1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Need help

Discussion in 'PHP & Perl' started by dadboss, Oct 19, 2008.

  1. dadboss

    dadboss BANNED BANNED

    Joined:
    Sep 29, 2007
    Messages:
    83
    Likes Received:
    52
    Hi
    I have a php function which use captchakiller.com api to solve every captcha
    I want to create a youtube account creator using that.
    What i want to add to my function :
    - use multiple api keys (because one api key = 30 captcha day)

    Heres the function :
    PHP:
    <?php
        
    //
        // Configuration
        //
        //Your API key
        
    $api_key 'B63A7848-D7B4-DE7E-E51E-CE1DD506AA78';

        
    //Path to captcha image
        
    $file getcwd() . '/captcha.jpg';

        
    //Url to CaptchaKiller API
        
    $url 'http://www.captchakiller.com/api.php';

        
        
    //
        // Functions
        //
        
    function upload_captcha($api_key$file)
        {
            global 
    $crl;

            
    $postdata = array(
                    
    'method'    => 'upload_captcha',
                    
    'api_key'    => $api_key,
                    
    'file'        => "@$file",
                    
    'expire'    => '300',
                    
    'rights'    => 'false'
                    
    );

            
    curl_setopt ($crlCURLOPT_POSTFIELDS$postdata);

            
    $result curl_exec($crl);
            
    $headers curl_getinfo($crl);

            if (
    $headers['header_size'] == 0)
            {
                
    curl_close($crl);
                die(
    'Upload Transaction failed');
            }
            else
            {
                echo 
    'Successfully uploaded captcha<br />';
            }

            
    //Parse captcha ID
            
    $pos strpos($result'SUCCESS: captcha_id=');
            
    $captcha_id 0;

            if(
    $pos !== false)
            {
                
    $pattern '([w-]+)';
                
    $matches = array();

                if(
    preg_match($patternsubstr($result20), $matches))    //20 = length of text before the ID
                
    {
                    
    $captcha_id $matches[0];
                    echo 
    'Captcha ID: ' $captcha_id '<br />';
                }
                else
                {
                    echo 
    'Could not find captcha id in: '' . $result . ''<br />';
                }
            }
            else
            {
                echo 
    $result;
            }
            
            return 
    $captcha_id;
        }

        function 
    get_result($api_key$captcha_id)
        {
            global 
    $crl;

            
    //Send request for captcha result
            
    $postdata = array(
                    
    'method'        => 'get_result',
                    
    'api_key'        => $api_key,
                    
    'captcha_id'    => $captcha_id
                    
    );

            
    curl_setopt ($crlCURLOPT_POSTFIELDS$postdata);

            
    $result curl_exec($crl);
            
    $headers curl_getinfo($crl);

            if (
    $headers['header_size'] == 0)
            {
                
    curl_close($crl);
                die(
    'Get Result transaction failed');
            }
            
            return 
    $result;
        }

        function 
    process_captcha($api_key$file$url)
        {
            
    $captcha_id upload_captcha($api_key$file$url);
            
    $captcha_result '';
            
            if(
    $captcha_id != 0)
            {
                echo 
    'Getting result';

                for(
    $i 0$i 20$i++)
                {
                    
    //Wait a few seconds before sending the next request
                    
    sleep(5);

                    
    //Get the result
                    
    $result get_result($api_key$captcha_id);

                    
    //Parse the result
                    
    $pos_success strpos($result'SUCCESS: captcha_result="');
                    
    $pos_wait strpos($result'WAIT: check back later');

                    if(
    $pos_success !== false)
                    {
                        
    $pattern '(.*)';
                        
    $matches = array();

                        if(
    preg_match($patternsubstr($result25), $matches))    //24 = length of text before the result
                        
    {
                            
    $captcha_result substr($matches[0], 0, -1);    //Trim off the trailing "
                            
    echo '<br />Captcha Result: ' $captcha_result '<br />';
                        }
                        else
                        {
                            echo 
    '<br />Could not find captcha result in: '' . $result . ''<br />';
                        }
                        break;
                    }
                    else if(
    $pos_wait !== false)
                    {
                        
    //WAIT found, try again
                        
    echo '.';
                        continue;
                    }
                    else
                    {
                        
    //FAILURE found
                        
    echo '<br />' $result;
                        break;
                    }

                    if(
    $i == 19)
                    {
                        echo 
    '<br />20 attempts have passed and still received WAIT<br />';
                    }
                }
            }
            
            return 
    $captcha_result;
        }
        
        
    //
        // Main program
        //
        // Start the cURL session
        
    $crl curl_init();
        
    curl_setopt($crlCURLOPT_URL$url);
        
    curl_setopt($crlCURLOPT_RETURNTRANSFER1);
        
        
    $captcha process_captcha($api_key$file$url);

        
    //Close the cURL session
        
    curl_close($crl);
    ?>

    Thx
     
  2. seomanifest

    seomanifest Regular Member

    Joined:
    Oct 5, 2008
    Messages:
    363
    Likes Received:
    81
    Occupation:
    Consultant
    Hi,

    This seems very interesting, but depending on an external service to break your api could be dangerous, your effort is probably better spent developing a remote captcha script that you could have a community fill out for you.
     
  3. PostWhore

    PostWhore Registered Member

    Joined:
    Jul 22, 2008
    Messages:
    51
    Likes Received:
    2
    Place API keys in the apikeys.txt file, one key per line. This code would run using one key 30 times. So if you got 10 keys, it will run 300 times. But it will upload the same captcha.jpg.

    PHP:
    <?php
        
    //
        // Configuration
        //
        //Your API key
        
    $keys file("apikeys.txt");
        
    //$api_key = 'B63A7848-D7B4-DE7E-E51E-CE1DD506AA78';

        //Path to captcha image
        
    $file getcwd() . '/captcha.jpg';

        
    //Url to CaptchaKiller API
        
    $url 'http://www.captchakiller.com/api.php';

        
        
    //
        // Functions
        //
        
    function upload_captcha($api_key$file)
        {
            global 
    $crl;

            
    $postdata = array(
                    
    'method'    => 'upload_captcha',
                    
    'api_key'    => $api_key,
                    
    'file'        => "@$file",
                    
    'expire'    => '300',
                    
    'rights'    => 'false'
                    
    );

            
    curl_setopt ($crlCURLOPT_POSTFIELDS$postdata);

            
    $result curl_exec($crl);
            
    $headers curl_getinfo($crl);

            if (
    $headers['header_size'] == 0)
            {
                
    curl_close($crl);
                die(
    'Upload Transaction failed');
            }
            else
            {
                echo 
    'Successfully uploaded captcha<br />';
            }

            
    //Parse captcha ID
            
    $pos strpos($result'SUCCESS: captcha_id=');
            
    $captcha_id 0;

            if(
    $pos !== false)
            {
                
    $pattern '([w-]+)';
                
    $matches = array();

                if(
    preg_match($patternsubstr($result20), $matches))    //20 = length of text before the ID
                
    {
                    
    $captcha_id $matches[0];
                    echo 
    'Captcha ID: ' $captcha_id '<br />';
                }
                else
                {
                    echo 
    'Could not find captcha id in: ' $result '<br />';
                }
            }
            else
            {
                echo 
    $result;
            }
            
            return 
    $captcha_id;
        }

        function 
    get_result($api_key$captcha_id)
        {
            global 
    $crl;

            
    //Send request for captcha result
            
    $postdata = array(
                    
    'method'        => 'get_result',
                    
    'api_key'        => $api_key,
                    
    'captcha_id'    => $captcha_id
                    
    );

            
    curl_setopt ($crlCURLOPT_POSTFIELDS$postdata);

            
    $result curl_exec($crl);
            
    $headers curl_getinfo($crl);

            if (
    $headers['header_size'] == 0)
            {
                
    curl_close($crl);
                die(
    'Get Result transaction failed');
            }
            
            return 
    $result;
        }

        function 
    process_captcha($api_key$file$url)
        {
            
    $captcha_id upload_captcha($api_key$file$url);
            
    $captcha_result '';
            
            if(
    $captcha_id != 0)
            {
                echo 
    'Getting result';

                for(
    $i 0$i 20$i++)
                {
                    
    //Wait a few seconds before sending the next request
                    
    sleep(5);

                    
    //Get the result
                    
    $result get_result($api_key$captcha_id);

                    
    //Parse the result
                    
    $pos_success strpos($result'SUCCESS: captcha_result="');
                    
    $pos_wait strpos($result'WAIT: check back later');

                    if(
    $pos_success !== false)
                    {
                        
    $pattern '(.*)';
                        
    $matches = array();

                        if(
    preg_match($patternsubstr($result25), $matches))    //24 = length of text before the result
                        
    {
                            
    $captcha_result substr($matches[0], 0, -1);    //Trim off the trailing "
                            
    echo '<br />Captcha Result: ' $captcha_result '<br />';
                        }
                        else
                        {
                            echo 
    '<br />Could not find captcha result in: ' $result '<br />';
                        }
                        break;
                    }
                    else if(
    $pos_wait !== false)
                    {
                        
    //WAIT found, try again
                        
    echo '.';
                        continue;
                    }
                    else
                    {
                        
    //FAILURE found
                        
    echo '<br />' $result;
                        break;
                    }

                    if(
    $i == 19)
                    {
                        echo 
    '<br />20 attempts have passed and still received WAIT<br />';
                    }
                }
            }
            
            return 
    $captcha_result;
        }
        
        
    //
        // Main program
        //
        // Start the cURL session
        
        
        
        
    for($i=0;$i<count($keys);$i++){
            for(
    $j=0;$j<30;$j++){
                
    $crl curl_init();
                
    curl_setopt($crlCURLOPT_URL$url);
                
    curl_setopt($crlCURLOPT_RETURNTRANSFER1);
                
                
    $captcha process_captcha($keys[$i], $file$url);
            
                
    //Close the cURL session
                
    curl_close($crl);            
            }
        }

    ?>


    The right way to do it, is to call api only when you download a new captcha image.

    P.S. I'm sure captchakiller is tracking IPs accessing their service.
     
    • Thanks Thanks x 1