Subscibe our Newsletter for FREE and stay up to date with our daily lesson*

How to Make CAPTCHA

CAPTCHA comes from words : Completely Automated Public Turing-test to tell Computers And Humans apart. As the meaning of that sentence, it is being used over hundreds pages to avoid automated requests from any scripts, (especially on registration forms).

Captcha codes were restored in current page’s session and uses PHP scripts to produce image containing the code. The visitor’s computer would not be able to read it. The one who able to read is human, in this case, is the visitor itself.

You need PHP to generate captcha code and store it in current session. Here is the example of the single one :

<?php
session_start();
$str = substr(md5(microtime()),0,8);
$_SESSION["captcha"] = $str;
$img = imagecreate(100,30);
$color = imagecolorallocate($img,59,89,153);
imagestring($img,10,10,10,$str,$color);
imagejpeg($img);
?>

Definition

  1. Session_start will ask server to start the session for your computer
  2. MD5 Microtime will generate randomized alpha numerical letter.
  3. Substr will cut your current randomized letter to 8 digits (i.e.)
  4. $_SESSION will store the letter in session with name “captcha” (i.e.)
  5. ImageCreate will surely create solid image with width 100px and height 30px.
  6. ImageColorAllocate colorize your generated image
  7. ImageString will write the letter to your generated image
  8. ImageJPEG will render the image and text within it as true image, the browser also treat this PHP file as JPEG image.

Save the current PHP document to (i.e.) captcha.php

Insert CAPTCHA to Page

The next task is pretty easy. You just have to load captcha.php using img tag. Here is the simple HTML Code :

<html>
<body>
<img src="http://yoursite.com/captcha.php" />
</body>
</html>

Let's talk it out!

4 Responses to “How to Make CAPTCHA”

  • jul

    this is inspiring


  • Arie Putranto

    That will produce the image obviously,also it is dynamic.


  • dimassimo

    simple way to make a CAPTCHA

    thanks julian


  • top article submission sites

    So CAPCTHA is so easy, isn’t it?


What is in your mind ?

Subscribe Me

Learn more the basic tips about WordPress and PHP coding. You can subscribe to our Newsletter to stay in touch with every new stories FREE

Sponsors

WooThemes - Where there's a Woo, there's a way!

Our FaceBook (new)


Discussion Topics

Who am I ?

My name is Julian Widya Perdana. I study at University of Gadjah Mada, Yogyakarta. I am a young developer addicted in JavaScript, Plugins, Themes, AJAX, and PHP developement. If you need anything, then submit it on Contact Us. If you feel satisfy with my work, please support me to keep it developed

Our Community

Discussion

Bibiana

Hi, I would like to know if I can post an attachment specific image with code. I've tried this,

Network Camera

Hi there, anyway, thanks for the info!

iYingHang

Thanks the tips. I am going to try it out. =)
Close