Hi
can any one give me the link for any good site for the code refference for generating Security Image in PHP??!!
Thanks,
Srikanth.
Need Code for generating Security Image
Moderator: General Moderators
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
- nickman013
- Forum Regular
- Posts: 764
- Joined: Sun Aug 14, 2005 12:02 am
- Location: Long Island, New York
Here is a very simple one:If you want audio backup check out http://bokehman.com/captcha_verification
Code: Select all
<?php
session_start();
if(isset($_GET['i'])){
// image creation section
captcha_image();
}elseif(isset($_POST['captcha'])){
// validation section
echo(captcha_validate())?'That was correct.<br>':'That was not correct.<br>';
echo '<a href="http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'">Try another?</a>';
exit;
}else{
// form section
echo
'<img src="http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?i='.uniqid().'" alt=""><br>'."\n".
'<form action="http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'" method="POST">'."\n".
'<input type="text" name="captcha" ><input type="submit" value="test it"></form>';
}
function captcha_validate()
{
return($_POST['captcha'] == $_SESSION['captcha']);
}
function captcha_image()
{
$_SESSION['captcha'] = substr(uniqid(), 0, ;
$image = imagecreate(80, 20);
$background_colour = imagecolorallocate($image, 255,255,255);
$text_shadow = imagecolorallocate($image, 127,127,127);
$text_colour = imagecolorallocate($image, 0,0,0);
imagestring($image, 5, 1, 1, $_SESSION['captcha'], $text_shadow);
imagestring($image, 5, 0, 0, $_SESSION['captcha'], $text_colour);
header ('Content-type: image/png');
imagepng($image, null, 100);
imagedestroy($image);
exit;
}
?>- nickman013
- Forum Regular
- Posts: 764
- Joined: Sun Aug 14, 2005 12:02 am
- Location: Long Island, New York