Hi, I've got a form with captcha working, but I'm trying to add a 'refresh captcha' link too it. Now I already have something changing dynamically with PHP so I was wondering if something like that would work for this. Here's the one I have working:
<a href="index.php?act=generate_quotes">Generate</a>
This obviously calls the function 'generate quotes. This works fine, but is there anyway to add a link to call something like this:
<?php
session_start();
$sha1 = SHA1(rand(2000,999000));
$letters = mt_rand(5,8);
$key = '';
for($i = 0; $i < $letters; $i++){
$pos = mt_rand(0, strlen($sha1)-1);
$key .= substr($sha1, $pos, 1);
}
$_SESSION['captcha'] = $key;
$w = 320;
$h = 100;
$r = mt_rand(160, 255);
$g = mt_rand(160, 255);
$b = mt_rand(160, 255);
$captcha = imagecreate($w, $h);
$background = imagecolorallocate($captcha, 255,255,255);
$text = imagecolorallocate($captcha, $r-128, $g-128, $b-128);
$dots = imagecolorallocate($captcha, 84,84,84);
for($i = 0; $i < 1700; $i++) {
imagefilledellipse($captcha, mt_rand(0,$w), mt_rand(0,$h), 1,
1, $dots);
}
for($i = 1; $i <= $letters; $i++){
$counter = mt_rand(0, 1);
if ($counter == 0){
$angle = mt_rand(0, 30);
}
if ($counter == 1){
$angle = mt_rand(330, 360);
}
imagettftext($captcha, 40, $angle, ($i * 18)-8, 70, $text, "iskpota.ttf", substr($key, ($i - 1), 1));
}
imageline($captcha, 0, mt_rand(5, $h-5), $w, mt_rand(5, $h-5), $text);
imagerectangle($captcha, 0, 0, $width - 1, $height - 1, $text);
function Blur($im)
{
$width = imagesx($im);
$height = imagesy($im);
$temp_im = ImageCreateTrueColor($width,$height);
$bg = ImageColorAllocate($temp_im,150,150,150);
ImageColorTransparent($temp_im,$bg);
ImageFill($temp_im,0,0,$bg);
$distance = 1;
ImageCopyMerge($temp_im, $im, 0, 0, 0, $distance, $width, $height-$distance, 70);
ImageCopyMerge($im, $temp_im, 0, 0, $distance, 0, $width-$distance, $height, 70);
ImageCopyMerge($temp_im, $im, 0, $distance, 0, 0, $width, $height, 70);
ImageCopyMerge($im, $temp_im, $distance, 0, 0, 0, $width, $height, 70);
// remove temp image
ImageDestroy($temp_im);
return $im;
}
Blur($captcha);
header('Expires: Tue, 08 Oct 1991 00:00:00 GMT');
header('Cache-Control: no-cache, must-revalidate');
header("Content-Type: image/gif");
imagegif($captcha);
imagedestroy($captcha);
?>
The above code is my capture .PHP - I've tried adding a function too it and calling it the same way, but to no avail, could someone help me out with how to go about doing this? I've never really used sessions so I'm not sure how to call them in the same way...
thanks for any help.