Captcha V1
Creating a CAPTCHA with PHP :: PHP Tutorial
This tutorial will show you how to create a form with Captcha. 1.Sessions in PHP are started by using the session_start() function. Like the setcookie( ) function, the session_start( ) function must come before any HTML, including blank lines, on the page.Code:
<?php session_start(); ?>
Code:
$img = imagecreatefrompng('black.png');
Code:
$white = imagecolorallocate($img, 255, 255, 255);
Code:
$numero = rand(100, 999);
Code:
if(($_POST['check']) == $_SESSION['check'])
{ echo 'Input OK';
}else{
echo 'Input Wrong';
}
Files
black.png

index.php:
Code:
<form method="POST" action="cc.php">
<img src="captchas.php"> <br>
<input type="text" size="10" name="check"> <br>
<input type="submit" name="submit" value="submit">
</form>
Code:
<?php session_start();
//imagecreatefrompng :: create a new image
//from file or URL
$img = imagecreatefrompng('black.png');
//displaying the random text on the captcha
$numero = rand(100, 999);
$_SESSION['check'] = ($numero);
//The function imagecolorallocate creates a
//color using RGB (red,green,blue) format.
$white = imagecolorallocate($img, 255, 255, 255);
imagestring($img, 10, 8, 3, $numero, $white);
header ("Content-type: image/png"); imagepng($img);
?>
Code:
<?php
//Sessions in PHP are started by using the
//session_start() function.
//Like the setcookie( ) function,
//the session_start function must come before any HTML,
//including blank lines, on the page.session_start();
//Check if the security code and
//the session value are not blank
//and if the input text matches the stored text
if(($_POST['check']) == $_SESSION['check']) {
echo 'Input OK';
}else{
echo 'Input Wrong';
}
PHP Comments
Padmashri 2010-08-27 02:14:39
Thanks for this php code.it's very helpful for me.
Alif 2010-07-27 17:05:13
it's nice tutorial, thanks for share the code
sivaramakrishnan 2010-07-12 02:04:44
Nice,its very useful for me to creating it.
Svolte 2010-06-07 12:32:25
Thanks a bunch for this script, its really helpful! :)
powered by phpform.net
discuss this topic to forum