Thursday, 18 September 2014

How to create CAPTCHA image verification in PHP and jQuery

How to create CAPTCHA image verification in PHP and jQuery

Captcha is the simple verification on your web forms that the user is a human or a computer. Its used to prevent spammerson your website. If you use captcha on your web forms its hard for spam bots to submit data to web site. The reason to write this tutorial is to demonstrate how to create captcha image in your application using PHP and jQuery.
CAPTCHA image verification in PHP and jQuery
We have used Fonts to generate text and create a random alpha-numeric word with background texture to prevent OCR readers. Used GD library to generate images.
index.php
File contains PHP code to load captcha image and text box to input visible word.
HTML is mixed to show image and input box and accept post data on the same page to verify. Create session of given captcha word once you submit that word it check that word with saved session word. Include jQuery library to reload captcha image onClick event $(“#captcha”).attr(“src”, “captcha.php?”+Math.random()); this line change src of visible image captcha.php generate captcha image every time it generate random word.
Check submitted word if match then show valid else invalid.
captcha.php
File contains PHP Code to generate captcha image.
This file create image with random string and show in png format on form $captcha = new CaptchaSecurityImages(145, 35, rand(4, 6)); width and height given with random number of latter here we select 4,6 it randomly show 4-6 latter captcha.
Hope you found this tutorial helpful please comment your views and problem faced in configuration.

No comments:

Post a Comment