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

PHP Captcha Handler

Discussion in 'PHP & Perl' started by Blaatje, Jan 12, 2011.

  1. Blaatje

    Blaatje Power Member

    Joined:
    Aug 17, 2010
    Messages:
    522
    Likes Received:
    110
    Location:
    NL
    Hi,

    I'm working on a SEO suite in PHP(personal use) and I would like to have a script that can enable me to fill out given captchas. I don't need some auto-breaker or something... I just want whenever my script makes an account somewhere, and a captcha shows up, the script stalls(while loop or something) and gives me the possibility to manually fill in the captcha.

    Anyone know of a piece of code to do this?

    Thanks!
     
  2. mazgalici

    mazgalici Supreme Member

    Joined:
    Jan 2, 2009
    Messages:
    1,489
    Likes Received:
    881
    Home Page:
    There are free libs for many programming languages on the sites who provide captcha breaking
     
  3. mazgalici

    mazgalici Supreme Member

    Joined:
    Jan 2, 2009
    Messages:
    1,489
    Likes Received:
    881
    Home Page:
  4. Blaatje

    Blaatje Power Member

    Joined:
    Aug 17, 2010
    Messages:
    522
    Likes Received:
    110
    Location:
    NL
    Thanks for your answer, mazgalici.

    But, like I tried explaining in my OP, I don't need/want captcha breaking for now. I want to be able to do it manually, by filling in a popup or something and then letting the script continue.
     
  5. ara_kopru

    ara_kopru Newbie

    Joined:
    Jan 29, 2011
    Messages:
    13
    Likes Received:
    0
    he wants to fill captcha by his hand.
     
  6. headliner

    headliner Registered Member

    Joined:
    Oct 2, 2009
    Messages:
    51
    Likes Received:
    5
    Not sure this can be done in PHP. You would be basically waiting for user input. Because PHP is a server side language, and as a result cannot do client side functions. Something to explore with AJAX or a mashup shell/php script. You will have to take in account the max execution time in PHP and the amount of memory you will consume as well.

    -HL
     
    Last edited: Feb 1, 2011
  7. Autumn

    Autumn Elite Member

    Joined:
    Nov 18, 2010
    Messages:
    2,197
    Likes Received:
    3,041
    Occupation:
    I figure out ways to make money online and then au
    Location:
    Spamville
    It depends on whether you are doing it with apache or the CLI.

    Assuming you're using the CLI, when you come across your captcha:

    save the captcha image locally (using curl etc)
    open the captcha using your image viewer of choice
    in your CLI PHP app, use this code to be able to enter the captcha value from the command line and then send it back to your app:
    PHP:
            echo "Enter the captcha:\n";
            
    $captcha_value fgets(STDIN);
            echo 
    "Value: $captcha_value\n";
    You can send $captcha_value to the next form filling / posting part of your script.

    If you are using apache, instead of using fgets() you would display the saved captcha image in your browser along with a one field form for entering the captcha value.
     
  8. headliner

    headliner Registered Member

    Joined:
    Oct 2, 2009
    Messages:
    51
    Likes Received:
    5
    Not sure what the benefit would be at that point. You would still have to bump the max script execution time to account for opening the file, etc... I guess you can always parse, find the captcha and repost like Autumn suggested, but it would be doing the work 2 times?

    -HL
     
  9. Autumn

    Autumn Elite Member

    Joined:
    Nov 18, 2010
    Messages:
    2,197
    Likes Received:
    3,041
    Occupation:
    I figure out ways to make money online and then au
    Location:
    Spamville
    If you're using the CLI you can open an image viewer from the CLI depending on your platform and choice of image viewer. I do this all the time when I am testing scripts that require captchas, so I don't have to wait for the captcha solving service to solve the captcha during the testing phase. Then I slot in the captcha solving functions when I know the rest of the code is correct.

    If you want to manually fill in captchas all the time then using apache is a very smooth and unobstructive way to do it, you can eliminate all the typing and clicking except for filling in the captcha.

    You can set max_execution_time = 0 or use set_time_limit(0) to eliminate timeouts.

    Are you sure you actually know PHP?
     
  10. Blaatje

    Blaatje Power Member

    Joined:
    Aug 17, 2010
    Messages:
    522
    Likes Received:
    110
    Location:
    NL
    As suggested by autumn, time-outs can be eliminated. I'm working with apache. I will try and search for sample code where captcha's are handled, but I have done that when I opened this thread also... if I find something useful, I'll obviously post it here. Thanks for all the feedback!
     
  11. gimme4free

    gimme4free Executive VIP Jr. VIP Premium Member

    Joined:
    Oct 22, 2008
    Messages:
    1,879
    Likes Received:
    1,932
    Easy:
    PHP:
    <?php
    if(isset($_POST['answer'])){
        
    $answer $_POST['answer'];
        
    // Retrieve other variables that may still be required that were run in the first script here
        // Continue process with captcha answer
        
    }
    // Run code here that gets the captcha image & save image to captcha.jpg
    echo "What does this image say: <img src='captcha.jpg' />";
    echo 
    "<form action='' method='post'><input type='text' name='answer' /><input type='submit' value='Continue' /></form>";
    ?>
    Simply run the script as per normal & get the captcha image, then echo out a form which shows and asks for the answer to the captcha & also keep any data that the script used in the first process in hidden form fields & then retrieve them and reuse the lot. I have done this in the past with loads of sites, only takes a few mins to knock up but if I were you I'd still go for Decaptcher as it will be faster for you in the long run, it gets extremely boring answering captchas!
     
  12. rjaus

    rjaus Newbie

    Joined:
    Apr 23, 2010
    Messages:
    35
    Likes Received:
    4
    for 1.39 per 1000 you really have to decide what your time is worth. I was thinking about going down this route but decided to go with deathbycaptcha in the end.

    Like someone already posted, they have an api that is REALLY simple to implement and then all your captcha's are done.

    Even if your only going to do 1000 captcha's, their API + $1.40 and the job is done.
     
  13. Blaatje

    Blaatje Power Member

    Joined:
    Aug 17, 2010
    Messages:
    522
    Likes Received:
    110
    Location:
    NL
    I understand your point of view, but besides the use of this and my scripts, I also am trying to get better and getting to know more complex PHP. So this has more advantages than a simple script to handle captcha's. :)
     
  14. Blaatje

    Blaatje Power Member

    Joined:
    Aug 17, 2010
    Messages:
    522
    Likes Received:
    110
    Location:
    NL
    Thanks for the code snippet. The real hard part, at least I imagine, would be the "//run code here to..." and how to keep a curl session live for filling in the captcha.

    Will search for a snippet to download the image right now :)
     
  15. Blaatje

    Blaatje Power Member

    Joined:
    Aug 17, 2010
    Messages:
    522
    Likes Received:
    110
    Location:
    NL
    Ok, quoting myself :D. After a minute of search I came across the perfect way to download and save an image.

    Code:
    $ch = curl_init([COLOR=#800000]'http://example.com/image.php'[/COLOR]); 
    $fp = fopen([COLOR=#800000]'/my/folder/captcha.gif'[/COLOR], [COLOR=#800000]'wb'[/COLOR]); 
    curl_setopt($ch, CURLOPT_FILE, $fp); 
    curl_setopt($ch, CURLOPT_HEADER, [COLOR=#800000]0[/COLOR]); 
    curl_exec($ch); 
    curl_close($ch); 
    fclose($fp); 
    
    Now I'll go about implementing it AND making it work the way I like... which will be the hard part :D
     
  16. gimme4free

    gimme4free Executive VIP Jr. VIP Premium Member

    Joined:
    Oct 22, 2008
    Messages:
    1,879
    Likes Received:
    1,932
    Also to keep sessions use cookies:
    PHP:
    curl_setopt($chCURLOPT_COOKIEJARstr_replace('\\','/',dirname(__FILE__)).'/cookies/account.txt');
    curl_setopt($chCURLOPT_COOKIEFILEstr_replace('\\','/',dirname(__FILE__)).'/cookies/account.txt');
     
  17. RottenYellow

    RottenYellow BANNED BANNED

    Joined:
    Sep 10, 2010
    Messages:
    68
    Likes Received:
    16
    I use CLI only for my PHP scripts. I'm doing it exactly the same way Autumn is doing, but I suggest you to get decaptcher or similar service. You can make your script ask for manual captcha input when you run out of decaptcher ;)