PHP Form.net
Free PHP Forms and Scripts

PHP Scripts

LinkBase 1.1.
Comments 1.1.
Meta Tags Generator 1.1.
E-Cards 1.1.
Feedback Form with Captcha
Tell A Friend
Contact Us - PHP Form
HTML Button Generator
PopUp Window Code Generator
Site Recommendation
ShoutBox 1.1.

PHP Tutorials

Creating a CAPTCHA with PHP
Bad Word Filter with PHP

Sponsor


Links

JaRobot.com
OWD :: 40070.org
www.metaTageEn.com
PHP Resource Index
Pixel2Life.com

Creating a CAPTCHA with PHP

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(); ?>
2.Imagecreatefrompng :: create a new image from file or URL.
Code:
$img = imagecreatefrompng('black.png'); 
3.The function imagecolorallocate creates a color using RGB (red,green,blue) format.
Code:
$white = imagecolorallocate($img, 255, 255, 255); 
5.Displaying the random text on the captcha image
Code:
$numero = rand(100, 999);
4.Check if the security code and the session value are not blank and if the input text matches the stored text.
Code:
if(($_POST['check']) == $_SESSION['check']) 
{ echo 'Input OK';
}else{ 
echo 'Input Wrong';        
}

Creating a CAPTCHA with PHP



black.png (40 x 20 pixels}


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>
captchas.php
Code:
<?php session_start(); 
//imagecreatefrompng :: create a new image 
//from file or URL
$img imagecreatefrompng('black.png'); 
//displaying the random text on the captcha 
image$numero rand(100999); 
$_SESSION['check'] = ($numero); 
//The function imagecolorallocate creates a 
//color using RGB (red,green,blue) format.
$white imagecolorallocate($img255255255); 
imagestring($img1083$numero$white);
 
header ("Content-type: image/png"); imagepng($img); 
?>
cc.php
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';        
}

discuss this topic to forum

01/01/08