₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,329,106 members, 8,438,823 topics. Date: Saturday, 04 July 2026 at 02:58 AM

Toggle theme

How To Implement Captcha(made Simple On Procedural Php) - Webmasters - Nairaland

Nairaland ForumScience/TechnologyWebmastersHow To Implement Captcha(made Simple On Procedural Php) (1831 Views)

1 Reply

How To Implement Captcha(made Simple On Procedural Php) by ebottabi(op): 7:09pm On Sep 26, 2008
this is how to implement a simple captcha on one's site,
first create an index.php file then insert these code:

<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>ebot tabi Captcha</title>
<link href="style/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="main">
<div class="caption"> CAPTCHA DEMO</div>
<div id="icon">&nbsp;</div>
<?php
if (isset($_POST['submitBtn'])){
$secCode = isset($_POST['secCode']) ? strtolower($_POST['secCode']) : "";
if ($secCode == $_SESSION['securityCode']) {
echo "<p>The result code was valid!<br/></p>";
echo "<p><a href=\"".$_SERVER['PHP_SELF']."\">Repeat the test!</a><br/><br/></p>";
unset($_SESSION['securityCode']);
$result = true;
}
else {
echo "<p>Sorry the security code is invalid! Please try it again!</p>";
$result = false;
}
}

if ((!isset($_POST['submitBtn'])) || (!$result)){
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" >
<table width="400">
<tr><td>Security code: <input class="text" name="secCode" type="text" size="10" /></td>
<td><img src="security.php" alt="security code" border="1" /></td>
</tr>
<tr><td colspan="2" align="center"><br/><input class="text" type="submit" name="submitBtn" value="Send" /></td></tr>
</table>
</form>
<?php
}
?>
<div id="source">Design by Ebot Tabi</div>
</div>
</body>




then create another file called sercurity.php
then insert these code:
<?php
session_start();

$width = 120;
$height = 40;
$length = 5;

$baseList = '0123456789abcdfghjkmnpqrstvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';

$code = "";
$counter = 0;

$image = @imagecreate($width, $height) or die('Cannot initialize GD!');

for( $i=0; $i<10; $i++ ) {
imageline($image,
mt_rand(0,$width), mt_rand(0,$height),
mt_rand(0,$width), mt_rand(0,$height),
imagecolorallocate($image, mt_rand(150,255), mt_rand(150,255), mt_rand(150,255)));
}

for( $i=0, $x=0; $i<$length; $i++ ) {
$actChar = substr($baseList, rand(0, strlen($baseList)-1), 1);
$x += 10 + mt_rand(0,10);
imagechar($image, mt_rand(3,5), $x, mt_rand(5,20), $actChar,
imagecolorallocate($image, mt_rand(0,155), mt_rand(0,155), mt_rand(0,155)));
$code .= strtolower($actChar);
}

header('Content-Type: image/jpeg');
imagejpeg($image);
imagedestroy($image);

$_SESSION['securityCode'] = $code;

?>


just follow the codes they quite simple
1 Reply

The Meaning Of CAPTCHA & 6 Types Of CAPTCHAProcedural Vs Object Oriented PHPHow To Use Ajax For Image Verification Aka CAPTCHA234

Flat-sql - An Ultra-light Weight Database Engine :: Php StuffVirtual Reality On A WebsiteHow To Make At Least $3 This Month