Menu

Adding Captcha

Help
Greg
2006-11-27
2013-06-03
  • Greg

    Greg - 2006-11-27

    Hi guys, have been trying to add Captcha and came across some code that may help but I cannot get it working properly, hope someone can help, it is based on a post at http://www.osticket.com/forums/showthread.php?t=2153&highlight=captcha

    --------------------------------------------------------------------------------

    Create a file named : randomImage.php in the same folder where process.php resides:

    <?php
    session_start();

    // generate 5 digit random number
    $rand = rand(10000, 99999);

    // create the hash for the random number and put it in the session
    $_SESSION['image_random_value'] = md5($rand);

    // create the image
    $image = imagecreate(60, 25);

    // use white as the background image
    $bgColor = imagecolorallocate ($image, 255, 255, 255);

    // the text color is black
    $textColor = imagecolorallocate ($image, 0, 0, 0);

    // write the random number
    imagestring ($image, 5, 5, 8, $rand, $textColor);

    // send several headers to make sure the image is not cached
    // taken directly from the PHP Manual

    // Date in the past
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");

    // always modified
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");

    // HTTP/1.1
    header("Cache-Control: no-store, no-cache, must-revalidate");
    header("Cache-Control: post-check=0, pre-check=0", false);

    // HTTP/1.0
    header("Pragma: no-cache");

    // send the content type header so the image is displayed properly
    header('Content-type: image/jpeg');

    // send the image to the browser
    imagejpeg($image);

    // destroy the image to free up the memory
    imagedestroy($image);
    ?>

    --------------------------------------------------------------------------------

    Add into form form field

    Verify: <img src="randomImage.php">
    <input id="txtNumber" name="txtNumber" type="text" value ="<-- type this number" onClick="document.forms[0].txtNumber.value='';"/>

    --------------------------------------------------------------------------------

    Add into process.php file (not sure where or if this is correct code

    $number = $_POST['txtNumber'];
    if (md5($number) != $_SESSION['image_random_value']) {
    $error .="You have provided an invalid security code.<br>";
    $errors=1;
    }

    --------------------------------------------------------------------------------

    Not sure how to get it working but hope the above will be a start to get someone with more knowledge to provide the chnages needed to get it to work.

    Cheers

    Greg

     
    • Musawir Ali

      Musawir Ali - 2006-12-27

      having image verification is a good idea, i think it would help considerably against spam. I will add this as a feature to the new phpFormGenerator version. My only concern is that all ISPs don't have gd support, which might cause problems with the image generation.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.