Captcha Code PHP Example Script | Secure Form PHP

By | September 11, 2013

Captcha Code php example

Today i am going to Explain about making the Captcha Code PHP. This is the step by step tutorial for making the captcha code for your project. You can use the script in your project.

In this tutorial we will use the GD Library of PHP. So check out your PHP and get assured that your GD library is enabled in PHP.

In captcha code php example tutorial we will not use any HTML form we will just provide you the running Captcha code.

Step 1. Define some constants.

One Phrase for getting the random text.

Step 2. Generate Random Text

Now we will generate the random text and save it in the pass_phrase variable.

In above code rand() is used for getting the random values from 97 to 122. It will loop till the Captcha_Numbers constant that is 7 so it will give us the 7 numbers. After getting the Numbers chr() function will change the number into character. As you can see we are taking 97 to 122 these are alphabets in ASCII. and chr() change the ASCII value to character. So after the whole loop process we will have the 7 random characters.

Step 4. Create the Image.

Above code will create an image with the Constants values.

Step 3. Set color variables for Background, text, and graphic color

$bgcolor – Will set the image background.

$textcolor- Will set the text color above the image.

$graphic color- Will set the graphic color for making the Captcha more strong.

In last line we will create a rectangle and set our $img to it. With constant values and background color.

Now we have the text, background color, text color, graphic color and rectangle but still we are missing the font. So we will use a font for it. Just copy and paste a font file in your project and link it to the $font.

Here i am using the arial narrow fornt.


Hope you like the Captcha Code PHP Example Script

~~~~ Happy Codeing ~~~~

4 thoughts on “Captcha Code PHP Example Script | Secure Form PHP

  1. Pingback: Create Thumbnail Image Dynamically Using PHP

  2. zanyar

    hi please tell me how can i make archive for my webfor example:jun 1998july 1998……agust 1997

    1. Vivek Moyal Post author

      If you are asking for wordpress than there is a widget which will do it for you. Else you have to create the logic for your content which is coming from your DB

  3. Pingback: Create Thumbnail PHP Script

Leave a Reply

Your email address will not be published. Required fields are marked *