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

Thread: Creation of captcha / Part II /Secure forms

  1. #1
    Jaan Guest

    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 Attached Files
    Last edited by Jordan; 05-07-2008 at 10:00 AM.

  2. CODECALL Circuit advertisement

     
  3. #2
    Join Date
    Mar 2008
    Location
    The North Pole
    Posts
    13,174
    Blog Entries
    13
    Rep Power
    114

    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

  4. #3
    Jaan Guest

    Re: Creation of captcha / Part II /Secure forms

    thanks

  5. #4
    Join Date
    Jul 2006
    Location
    Amherst, New York, United States
    Posts
    6,277
    Blog Entries
    26
    Rep Power
    20

    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...

  6. #5
    Join Date
    Mar 2008
    Location
    The North Pole
    Posts
    13,174
    Blog Entries
    13
    Rep Power
    114

    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

  7. #6
    Metanet is offline Newbie
    Join Date
    May 2008
    Posts
    1
    Rep Power
    0

    Re: Creation of captcha / Part II /Secure forms

    Thanks for the tutorial

  8. #7
    knaleffect is offline Newbie
    Join Date
    May 2008
    Posts
    2
    Rep Power
    0

    Re: Creation of captcha / Part II /Secure forms

    Thank for the tutorial

  9. #8
    Jaan Guest

    Re: Creation of captcha / Part II /Secure forms

    you're welcome

  10. #9
    Join Date
    Aug 2006
    Posts
    11,209
    Blog Entries
    6
    Rep Power
    100

    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?

  11. #10
    Jaan Guest

    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..

+ Reply to Thread
Page 1 of 5 123 ... LastLast

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. 3D captcha - new captcha technology concept
    By Juraj Rolko in forum Technology Ramble
    Replies: 5
    Last Post: 07-25-2011, 03:44 PM
  2. Quick Tip 1 - Secure your forms against CSRF attacks
    By While1 in forum PHP Tutorials
    Replies: 0
    Last Post: 07-07-2010, 10:50 AM
  3. Creation of captcha
    By Jaan in forum PHP Tutorials
    Replies: 21
    Last Post: 03-22-2010, 04:01 AM
  4. Smarty - Part 2 - Smartify your Forms
    By Orjan in forum PHP Tutorials
    Replies: 4
    Last Post: 07-22-2009, 05:52 PM
  5. scripts on secure payment forms?
    By akuhl101 in forum Java Help
    Replies: 3
    Last Post: 04-18-2009, 11:37 PM

Tags for this Thread

Bookmarks

Posting Permissions

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