[PHP][Tutorial] Basic Capcha

Results 1 to 9 of 9
  1. #1
    Vous Pas Reel HotelUnderSeige is offline
    MemberRank
    Nov 2007 Join Date
    ColoradoSpringsLocation
    1,290Posts

    [PHP][Tutorial] Basic Capcha

    Well here it goes
    PHP Code:
    <? session_start();  ?>
    <?php
    $rawr 
    rand(10010000);
    $_SESSION['rawr'] = $rawr ;
    $capcha $rawr;
    ?>
    <? 
    echo("$rawr"); ?><form method="post" action="rawr.php">
    capcha: <input type="text" size="10" maxlenght="5" name="rawr"> 
    <input="sumbit">
    PHP Code:
    <? session_start(); ?>
    <?php
    $capcha 
    $_POST['rawr'];

    if ( 
    $capcha == $rawr ) {
        echo 
    "Thank you, you may proceed";
    } else {
        echo 
    "you /fail";
    }
    session_destroy();
    ?>
    Rand = Random, it will randomize the numbers through the varibles ( 100-1000)


    Ok so i have not used php in awhile so im not sure if i got all of the scripts
    right. So please post with your responses to the tutorial.
    Last edited by HotelUnderSeige; 15-12-08 at 07:07 AM.


  2. #2
    Account Upgraded | Title Enabled! Cask is offline
    MemberRank
    Jul 2007 Join Date
    887Posts

    re: [PHP][Tutorial] Basic Capcha

    Don't captchas usually use pictures?

  3. #3
    Vous Pas Reel HotelUnderSeige is offline
    MemberRank
    Nov 2007 Join Date
    ColoradoSpringsLocation
    1,290Posts

    re: [PHP][Tutorial] Basic Capcha

    Quote Originally Posted by Cask View Post
    Don't captchas usually use pictures?
    yes but this is a basic one. Or i would have used GD for the image, perhaps annother tutorial?

  4. #4
    Account Upgraded | Title Enabled! Cask is offline
    MemberRank
    Jul 2007 Join Date
    887Posts

    re: [PHP][Tutorial] Basic Capcha

    I've tried to make one with images, just now, and I'm having a bit of trouble trying to match the codes:

    Image.php
    PHP Code:
    <?php
        
    // load PNG image
        
    $image    imagecreatefrompng("http://forum.ragezone.com/images/captcha_background.png");
        
        
    // load font
        
    $font    "fonts/Tahoma.ttf";
        
        
    // add code
        /*$code    = rand(10, 100);
        $code    = $code . " " . rand(10, 100);
        $code    = $code . " " . rand(10, 100);
        $code    = $code . " " . rand(10, 100);*/
        
    $code    $_GET['code'];
        
        
    imagefttext($image3004057null$font$code);
        
        
    // show
        
    header("Content-Type: image/png, html");
        
    imagepng($image);
    ?>
    Index.php (Form)
    PHP Code:
    <html>
        <body>
            <?php $image_text rand(10100) . rand(10100) . rand(10100) . rand(10100);
                if (isset(
    $_POST['go']))
                {
                    
    $input_code    $_POST['input_code'];
                    
                    if (
    $input_code != $image_text)
                    {
                        echo 
    'You have entered an incorrect code, please try again.<br /><br />';
                    }
                    else
                    {
                        echo 
    'Congratulations, code successful!<br /><br />';
                    }
                }
            
    ?>
            <img src="image.php?code=<?php echo $image_text?>">
            <FORM METHOD="POST">
                <table>
                    <tr>
                        <td>
                            Type in the code from the above image:
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <input type="text" name="input_code">
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <input type="submit" name="go">
                        </td>
                    </tr>
                </table>
            </FORM>
        </body>
    </html>

  5. #5
    Member greenowl is offline
    MemberRank
    Jul 2005 Join Date
    New ZealandLocation
    76Posts

    re: [PHP][Tutorial] Basic Capcha

    Cask, you should try use a session to store the captcha data. Create the session in the image script and you can check the result in any of your other scripts.

  6. #6
    Account Upgraded | Title Enabled! Cask is offline
    MemberRank
    Jul 2007 Join Date
    887Posts

    re: [PHP][Tutorial] Basic Capcha

    Quote Originally Posted by greenowl View Post
    Cask, you should try use a session to store the captcha data. Create the session in the image script and you can check the result in any of your other scripts.
    Ah yes, thankyou, I'll try it after I have a flog, bbs.

    Edit, well that was quick, good porn.
    -

    Thanks Greenowl, your idea works.
    Script attatched.
    Includes:
    - index.php
    - image.php
    - images/captcha_background.png
    - fonts/Tahoma.ttf
    Attached Files Attached Files

  7. #7
    Status: Pooping eele is offline
    MemberRank
    Jul 2008 Join Date
    The NetherlandsLocation
    915Posts

    Re: [PHP][Tutorial] Basic Capcha

    Call to undefined function imagecreatefrompng()

  8. #8
    Account Upgraded | Title Enabled! Cask is offline
    MemberRank
    Jul 2007 Join Date
    887Posts

    Re: [PHP][Tutorial] Basic Capcha

    Quote Originally Posted by eele View Post
    Call to undefined function imagecreatefrompng()
    You may have to update your PHP, or if you have PHP 6.0.0, some of those functions may not work as it is GD1, it has since been upgraded to GD2.

    http://au.php.net/manual/en/image.setup.php

  9. #9
    Status: Pooping eele is offline
    MemberRank
    Jul 2008 Join Date
    The NetherlandsLocation
    915Posts

    Re: [PHP][Tutorial] Basic Capcha

    Quote Originally Posted by Cask View Post
    You may have to update your PHP, or if you have PHP 6.0.0, some of those functions may not work as it is GD1, it has since been upgraded to GD2.

    http://au.php.net/manual/en/image.setup.php
    Thnx.



Advertisement