<div class='codetop'>CODE</div><div class='codemain' style='height:200px;white-space:pre;overflow:auto'>
<?php
//This is php_captcha.php
// Make a simple jpg graphic (100x35 pixels or so) and save to the same space as this file
session_start();
$RandomStr = md5(microtime());// md5 to generate the random string
$ResultStr = substr($RandomStr,0,5);//trim 5 digit
$NewImage =imagecreatefromjpeg("captcha.jpg");//image create by existing image and as background
$LineColor = imagecolorallocate($NewImage,233,239,239);//line color
$TextColor = imagecolorallocate($NewImage, 255, 255, 255);//text color-white
imageline($NewImage,1,10,200,30,$LineColor);//create line 1 on image
imageline($NewImage,1,50,60,0,$LineColor);//create line 2 on image
imagestring($NewImage, 5, 20, 5, $ResultStr, $TextColor);// Draw a random string horizontally
$_SESSION['key'] = $ResultStr;// carry the data through session
header("Content-type: image/jpeg");// output the image
imagejpeg($NewImage);//Output image to browser
?>
Save this file to your webspace somewhere with a small jpg image of like 100 by 35 pixels or so (any color). Then within your forms where you want the user tested (to keep out automated bots and mass mailers), you place this additional code.
werever u want users to submit the code
<input name="captcha" type="text"> //Users will enter the code here
[img]php_captcha.php[/img] //This will produce the captcha image
After submitting the form, your PHP will verify the key they entered against the one saved in the user's SESSION tag.
......................in the next page or u wan c if the text entered is right o wrong
$key=substr($_SESSION['key'],0,5);
$captcha = $_POST['captcha'];
if ($key!=$captcha) {
// Error! The key did not match
} else {
// Success! Verification complete
}</div>
-------------------------------
NOTE: U CN FORM UR OWN IMAGE .....AS CAPTCHA.JPG
<?php
//This is php_captcha.php
// Make a simple jpg graphic (100x35 pixels or so) and save to the same space as this file
session_start();
$RandomStr = md5(microtime());// md5 to generate the random string
$ResultStr = substr($RandomStr,0,5);//trim 5 digit
$NewImage =imagecreatefromjpeg("captcha.jpg");//image create by existing image and as background
$LineColor = imagecolorallocate($NewImage,233,239,239);//line color
$TextColor = imagecolorallocate($NewImage, 255, 255, 255);//text color-white
imageline($NewImage,1,10,200,30,$LineColor);//create line 1 on image
imageline($NewImage,1,50,60,0,$LineColor);//create line 2 on image
imagestring($NewImage, 5, 20, 5, $ResultStr, $TextColor);// Draw a random string horizontally
$_SESSION['key'] = $ResultStr;// carry the data through session
header("Content-type: image/jpeg");// output the image
imagejpeg($NewImage);//Output image to browser
?>
Save this file to your webspace somewhere with a small jpg image of like 100 by 35 pixels or so (any color). Then within your forms where you want the user tested (to keep out automated bots and mass mailers), you place this additional code.
werever u want users to submit the code
<input name="captcha" type="text"> //Users will enter the code here
[img]php_captcha.php[/img] //This will produce the captcha image
After submitting the form, your PHP will verify the key they entered against the one saved in the user's SESSION tag.
......................in the next page or u wan c if the text entered is right o wrong
$key=substr($_SESSION['key'],0,5);
$captcha = $_POST['captcha'];
if ($key!=$captcha) {
// Error! The key did not match
} else {
// Success! Verification complete
}</div>
-------------------------------
NOTE: U CN FORM UR OWN IMAGE .....AS CAPTCHA.JPG
Comment