Page 1 of 1
Need Code for generating Security Image
Posted: Mon Feb 27, 2006 1:23 pm
by srikanth
Hi
can any one give me the link for any good site for the code refference for generating Security Image in PHP??!!
Thanks,
Srikanth.
Posted: Mon Feb 27, 2006 1:42 pm
by John Cartwright
do you mean CAPTCHA? as in they have to input a text based image into a field?
if so
to start you off
Posted: Mon Feb 27, 2006 2:35 pm
by srikanth
Thanks........

Posted: Mon Feb 27, 2006 3:04 pm
by nickman013
You might get problems, like no image appearing this is because your server may not support image creation functions.
In this case you would have to contact your host and ask them to enable it.
Posted: Mon Feb 27, 2006 6:23 pm
by bokehman
Here is a very simple one:
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;
}
?>
If you want audio backup check out
http://bokehman.com/captcha_verification
Posted: Mon Feb 27, 2006 8:59 pm
by nickman013
Thank you for that. It is perfect!
I dont know why I couldnt get the others to work, I kept on getting no picture.
Thanks!