Sunday, June 24, 2012

Google Like CAPTCHA with PHP.

Google Like CAPTCHA with PHP.

form.php
Contains HTML code image source captcha.php. File available in download script.
<form method="post"  action="reg.php">
<b>Name</b><br/>
<input type="text" name="name" /><br/>
<b>Message</b><br/>
<textarea name="message"></textarea><br/>
<img src="captcha.php" id="captcha" /><br/>
<a href="#" onclick="
document.getElementById('captcha').src='captcha.php?'+Math.random();
document.getElementById('captcha-form').focus();"
id="change-image">Not readable? Change text.</a><br/><br/>
<b>Human Test</b><br/>
<input type="text" name="captcha" id="captcha-form" /><br/&gt;
<input type="submit" />
</form>



reg.php
Contains PHP code 
<?php
session_start();
if (!empty($_REQUEST['captcha']))
{

if (empty($_SESSION['captcha']) ||trim(strtolower($_REQUEST['captcha'])) != $_SESSION['captcha'])
{
$note= 'Please enter correct text code';
}

else
{

if($_SERVER["REQUEST_METHOD"] == "POST")
{
$name=htmlentities($_POST['name']);
$message=htmlentities($_POST['message']);
// Insert SQL Statement 
$note= 'Values Inserted Successfully';
}

}
unset($_SESSION['captcha']);
}
?>

No comments:

Post a Comment