Simple php captcha

PHP Comments Off

CAPTCHA word comes from the word  “capture” and CAPTCHA stands for Completely Automated Public Turing test to tell Computers and Humans Apart“.A Captcha is a program that protects websites against bots by generating and grading tests that humans can pass but current computer programs cannot. Captcha allows you to protect your website from spam using math logic which can be used for login, registration, resetting password, comments forms etc.Some captcha’s are very complex and difficult to understand and implement.So here i like to share with you a simple four digits captcha which can be easily implemented.

<img id="captcha" title="Click to reload image" onclick="javascript:reloadCaptcha()" alt="Click to reload image" src="image.php" />
<input onclick="this.value=''" type="text" maxlength="4" name="secure" size="20" value="" />

The captcha reload javascript code  is:

<script type="text/javascript">// <![CDATA[
function reloadCaptcha()
 {
 document.getElementById('captcha').src = document.getElementById('captcha').src+ '?' +new Date();
 }
// ]]></script>

Additional files are attached here: captcha.rar

Corresponding php code to check captcha is as follows:

<?
if($_REQUEST['secure'] !=NULL)
 {
 if($_REQUEST['secure'] != $_SESSION['security_number'])
 {
 die("<b>Incorrect captcha</b>");
 }
 }
 else
 die("Access denied");
?>
The following two tabs change content below.
I am a core php developer and web designer working as a freelancer in elance,odesk etc.

Latest posts by Mudit (see all)

Comments are closed.

x
Loading...