Captcha

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Captcha

    <div class='codetop'>CODE</div><div class='codemain' style='height:200px;white-space:pre;overflow:auto'>
    <?php
    //This is php_captcha.php
    // Make a simple jpg graphic (100x35 pixels or so) and save to the same space as this file
    session_start();

    $RandomStr = md5(microtime());// md5 to generate the random string
    $ResultStr = substr($RandomStr,0,5);//trim 5 digit
    $NewImage =imagecreatefromjpeg("captcha.jpg");//image create by existing image and as background
    $LineColor = imagecolorallocate($NewImage,233,239,239);//line color
    $TextColor = imagecolorallocate($NewImage, 255, 255, 255);//text color-white
    imageline($NewImage,1,10,200,30,$LineColor);//create line 1 on image
    imageline($NewImage,1,50,60,0,$LineColor);//create line 2 on image
    imagestring($NewImage, 5, 20, 5, $ResultStr, $TextColor);// Draw a random string horizontally
    $_SESSION[&#39;key&#39;] = $ResultStr;// carry the data through session
    header("Content-type: image/jpeg");// output the image
    imagejpeg($NewImage);//Output image to browser

    ?>
    Save this file to your webspace somewhere with a small jpg image of like 100 by 35 pixels or so (any color). Then within your forms where you want the user tested (to keep out automated bots and mass mailers), you place this additional code.

    werever u want users to submit the code
    <input name="captcha" type="text"> //Users will enter the code here
    [img]php_captcha.php[/img] //This will produce the captcha image
    After submitting the form, your PHP will verify the key they entered against the one saved in the user&#39;s SESSION tag.

    ......................in the next page or u wan c if the text entered is right o wrong

    $key=substr($_SESSION[&#39;key&#39;],0,5);
    $captcha = $_POST[&#39;captcha&#39;];

    if ($key!=$captcha) {
    // Error! The key did not match
    } else {
    // Success! Verification complete
    }</div>
    -------------------------------

    NOTE: U CN FORM UR OWN IMAGE .....AS CAPTCHA.JPG

    #2
    i would strongly recommend the use of recaptcha .. i have and do like my own captcha mods however captchas are a security feature not a style feature... therefore go with something tried and tested by millions of websites and by billions of users. Plus each time you use it you help by digitizing paper based media

    sure your own captcha mod may be fine.. but the way i see it, if its a security mod to a site then use the most secure method of implementation

    Comment

    Working...
    X