Results 1 to 3 of 3

Thread: How to make HTML form with CAPTCHA?

  1. #1
    Junior Member
    Join Date
    Oct 2015
    Location
    orbikibly
    Posts
    6

    How to make HTML form with CAPTCHA?

    Dear all,
    I am facing a problem that how to make HTML form with CAPTCHA.
    Any help in this regard will appreciate.

    With Regards

  2. #2
    Super Moderator rlirpa's Avatar
    Join Date
    Feb 2014
    Location
    MD, US
    Posts
    464
    Rad

  3. #3
    Banned
    Join Date
    Feb 2016
    Location
    Delhi
    Posts
    10
    2
    down vote

    Step 1

    You need some code to generate a graphical font image representation web captcha. you must have GD library for generating font image.

    <?php
    session_start();
    $RandomStr = md5(microtime());
    $ResultStr = substr($RandomStr,0,5);
    $NewImage =imagecreatefromjpeg("bgimage.jpg");

    $LineColor = imagecolorallocate($NewImage,233,239,239);
    $TextColor = imagecolorallocate($NewImage, 255, 255, 255);
    imageline($NewImage,1,1,40,40,$LineColor);
    imageline($NewImage,1,100,60,0,$LineColor);

    $font = imageloadfont("font.gdf");
    imagestring ($NewImage, $font, 5, 5, $ResultStr, $TextColor );
    $_SESSION['originalkey'] = $ResultStr; //store the original coderesult in session variable

    header("Content-type: image/jpeg");
    imagejpeg($NewImage);
    ?>

    Step 2

    Now your form to call captcha.

    <form action="submit.php" method="post" name="form1">
    Name:
    <input type="text" name="name" value="" /> <br />
    Email Address:
    <input type="text" name="email" value="" /> <br />
    Message:
    <textarea name="message" cols="30" rows="6"></textarea> <br />
    <img src="php_captcha.php" />
    <input name="captcha" type="text" id="captcha" size="15" /> <br />

    <input type="submit" name="submit" value="Submit" />
    <input type="reset" name="reset" value="clear"/>
    </form>

    Step 3

    Now this is last step to form submiting time check capcha validation. Using session information.

    <?php
    $originalkey = substr($_SESSION['originalkey'],0,5); //session of captcha
    $captcha = $_REQUEST['captchacode'];
    if($captcha!=$originalkey){
    print_error("<b> Captcha does not match, Go back and try again.</b>");
    }
    ?>

Similar Threads

  1. Adding a better captcha
    By AaronMaxwell in forum Site Feedback/Questions/Suggestions
    Replies: 1
    Last Post: September 14th, 2012, 04:57 PM
  2. HTML Form help
    By codenamevirus in forum Web Development
    Replies: 4
    Last Post: January 17th, 2006, 11:29 PM
  3. how to make a form watcher parogram
    By cybermonk in forum Programming Security
    Replies: 5
    Last Post: June 25th, 2003, 09:00 PM

Posting Permissions

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