+ Reply to Thread
Page 1 of 5
1 2 3 ... LastLast
Results 1 to 10 of 48

Thread: Creation of captcha / Part II /Secure forms

  1. #1
    Moderator Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan's Avatar
    Join Date
    Dec 2006
    Location
    Estonia
    Age
    18
    Posts
    2,052
    Blog Entries
    9

    Creation of captcha / Part II /Secure forms

    Okay here's our code of this captcha image:

    Code:
    <?php
    header
    ('Content-type: image/jpg');
    $im imagecreatefromjpeg ("image.jpg");
    $rand1 rand(1,255);
    $rand2 rand(1,255);
    $rand3 rand(1,255);
    $color imagecolorallocate($im$rand1$rand2$rand3);
    $text rand(10009999);
    $font 'text-font.otf';
    $size 30;
    imagettftext($im$size07045$color$font$text);
    imagejpeg($im);
    imagedestroy($im);
    ?>
    But if we want to use this image on our sites we must add:

    Code:
    $_SESSION['captcha'] = $text
    on the bottom of our captcha file. So.. now let's make our form secure.

    First of all we must start the session

    Code:
    <?php
    session_start
    ();
    session_start(); - Starts the session

    Now I'm using a form for checking that is the security code correct

    Code:
    if(isset($_POST['submit'])){
    $ses $_SESSION['captcha'];
    if(
    $ses == $_POST['code']){
    echo 
    "Code is correct!";
    }else{
    echo 
    "Code is incorrect!";

    if(isset($_POST['submit']) && !empty($_POST['code'])){ - If someone has clicked the submit button let's continue with our script
    $ses = $_SESSION['captcha']; - Let's get the captcha code from the session
    if($ses == $_POST['code']){ - If captcha's code is same as the code you posted
    echo "Code is correct!"; - let's say that the code was correct
    }else{ - but if they are not same
    echo "Code is incorrect!"; - let's say that the code is not correct
    } - This ends the if and else statement

    Code:
    }else{
    echo 
    "<img src='captcha.php'><br>";
    echo 
    "<form action='' method='post'>"
        
    ."<input type='text' name='code'>"
        
    ."<input type='submit' name='submit' value='Enter'>"
        
    ."</form>";

    }else{ - If anyone hasnt clicked the submit button let's display our form
    echo "<img src='captcha.php'><br>"; - Shows our captcha image
    echo "<form action='' method='post'>"
    ."<input type='text' name='code'>"
    ."<input type='submit' name='submit' value='Enter'>"
    ."</form>";
    - Our form
    } - This ends the if and else statement



    And we are done.. that was so simple
    You can customize this script for your forms

    Here's the full script:

    captcha.php
    Code:
    <?php
    session_start
    ();
    $im imagecreatefromjpeg ("image.jpg");
    $rand1 rand(1,255);
    $rand2 rand(1,255);
    $rand3 rand(1,255);
    $color imagecolorallocate($im$rand1$rand2$rand3);
    $text rand(10009999);
    $font 'text-font.otf';
    $size 30;
    imagettftext($im$size07045$color$font$text);
    header('Content-type: image/jpg');
    imagejpeg($im);
    imagedestroy($im);
    $_SESSION['captcha'] = $text;
    ?>
    index.php
    Code:
    <?php
    session_start
    ();

    if(isset(
    $_POST['submit']) && !empty($_POST['code'])){
    $ses $_SESSION['captcha'];
    if(
    $ses == $_POST['code']){
    echo 
    "Code is correct!";
    }else{
    echo 
    "Code is incorrect!";
    }
    }else{
    echo 
    "<img src='captcha.php'><br>";
    echo 
    "<form action='' method='post'>"
        
    ."<input type='text' name='code'>"
        
    ."<input type='submit' name='submit' value='Enter'>"
        
    ."</form>";
    }
    ?>
    I attached the files also
    Enjoy!
    Attached Files
    Last edited by Jordan; 05-07-2008 at 12:00 PM.
    Trill Hosting - Cheap Web Hosting, Register Cheap Domains, Cheap Blog Hosting
    www.trillhosting.com | support@trillhosting.com
    Hosting Plans | Write To Us | Support | Client Area | About Us
    CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum | Freelance

  2. #2
    Xav
    Xav is offline
    Code Slinger Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav's Avatar
    Join Date
    Mar 2008
    Location
    The North Pole
    Posts
    13,210
    Blog Entries
    13

    Re: Creation of captcha / Part II /Secure forms

    Thanks, Jaan! There are various premade scripts available, but creating your own is easier to integrate.
    I think the other type of captchas are better, where it is just plain black text with a warped line through it. It does not require a background, and so fits in to web pages more smoothly. Nice tutorial, though.

    Quote Originally Posted by Jordan View Post
    Good members, like yourself, stick around and post for ages to come!
    Mr. Xav | Blog | Forums

  3. #3
    Moderator Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan's Avatar
    Join Date
    Dec 2006
    Location
    Estonia
    Age
    18
    Posts
    2,052
    Blog Entries
    9

    Re: Creation of captcha / Part II /Secure forms

    thanks
    Trill Hosting - Cheap Web Hosting, Register Cheap Domains, Cheap Blog Hosting
    www.trillhosting.com | support@trillhosting.com
    Hosting Plans | Write To Us | Support | Client Area | About Us
    CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum | Freelance

  4. #4
    Co-Administrator John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John is a glorious beacon of light John's Avatar
    Join Date
    Jul 2006
    Age
    21
    Posts
    5,883
    Blog Entries
    25

    Re: Creation of captcha / Part II /Secure forms

    Quote Originally Posted by Xav View Post
    Thanks, Jaan! There are various premade scripts available, but creating your own is easier to integrate.
    I think the other type of captchas are better, where it is just plain black text with a warped line through it. It does not require a background, and so fits in to web pages more smoothly. Nice tutorial, though.
    Those types of captchas are useless. I've considered writing a tutorial on how to bypass captchas like that...

  5. #5
    Xav
    Xav is offline
    Code Slinger Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav's Avatar
    Join Date
    Mar 2008
    Location
    The North Pole
    Posts
    13,210
    Blog Entries
    13

    Re: Creation of captcha / Part II /Secure forms

    Really? I thought it was difficult to distinguish the letters when there was a line through them? How about the fuzzy-letters one?

    Quote Originally Posted by Jordan View Post
    Good members, like yourself, stick around and post for ages to come!
    Mr. Xav | Blog | Forums

  6. #6
    Newbie Metanet is an unknown quantity at this point
    Join Date
    May 2008
    Posts
    1

    Re: Creation of captcha / Part II /Secure forms

    Thanks for the tutorial

  7. #7
    Newbie knaleffect is an unknown quantity at this point
    Join Date
    May 2008
    Posts
    2

    Re: Creation of captcha / Part II /Secure forms

    Thank for the tutorial

  8. #8
    Moderator Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan's Avatar
    Join Date
    Dec 2006
    Location
    Estonia
    Age
    18
    Posts
    2,052
    Blog Entries
    9

    Re: Creation of captcha / Part II /Secure forms

    you're welcome
    Trill Hosting - Cheap Web Hosting, Register Cheap Domains, Cheap Blog Hosting
    www.trillhosting.com | support@trillhosting.com
    Hosting Plans | Write To Us | Support | Client Area | About Us
    CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum | Freelance

  9. #9
    TcM
    TcM is offline
    Code Warrior TcM is a name known to all TcM is a name known to all TcM is a name known to all TcM is a name known to all TcM is a name known to all TcM is a name known to all TcM's Avatar
    Join Date
    Aug 2006
    Posts
    11,461
    Blog Entries
    6

    Re: Creation of captcha / Part II /Secure forms

    What about the captcha that rapidshare.com has? It has a captcha with 6 digits, but 4 of them have a cat behind them, and you have to write the ones with the cat... does that work the same way?

  10. #10
    Moderator Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan is a splendid one to behold Jaan's Avatar
    Join Date
    Dec 2006
    Location
    Estonia
    Age
    18
    Posts
    2,052
    Blog Entries
    9

    Re: Creation of captcha / Part II /Secure forms

    hmmm..this rapidshare thingy is really lame..
    that's why i bought a premium account..
    uumm.. i believe rapidshare uses a little trick there..
    Trill Hosting - Cheap Web Hosting, Register Cheap Domains, Cheap Blog Hosting
    www.trillhosting.com | support@trillhosting.com
    Hosting Plans | Write To Us | Support | Client Area | About Us
    CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum | Freelance

+ Reply to Thread
Page 1 of 5
1 2 3 ... LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Creation of captcha
    By Jaan in forum PHP Tutorials
    Replies: 19
    Last Post: 05-26-2009, 07:01 AM

Bookmarks

Bookmarks

     
        Algorithms and Data Structures

        Java tutorials

        Algorithms Forum

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts