Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,153,971 members, 7,821,400 topics. Date: Wednesday, 08 May 2024 at 12:28 PM

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

Nairaland Forum / Science/Technology / Webmasters / How To Implement Captcha(made Simple On Procedural Php) (1751 Views)

The Meaning Of CAPTCHA & 6 Types Of CAPTCHA / Procedural Vs Object Oriented PHP / How To Use Ajax For Image Verification Aka CAPTCHA (2) (3) (4)

(1) (Reply)

How To Implement Captcha(made Simple On Procedural Php) by ebottabi(m): 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)

Urgent Help! I Need Interswitch Api On My Website / Talk Bad About Google And Be Banned From Adsense And Search Results / Beware Of This Advert

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 13
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.