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.

Recommended Answers

All 4 Replies

I don't think that you have provided enough info for anyone to help you. The structure of your modules and how they relate to each other isn't clear. You could certainly add a link to call the above module but it isn't clear if this will accomplish what you need to do. Maybe you should be including this module instead. You don't call a session, it is just a facility that you can use to pass info between modules and keep info through a transaction sequence. If you provide a more complete explanation, someone may be able to help you.

I don't think that you have provided enough info for anyone to help you. The structure of your modules and how they relate to each other isn't clear. You could certainly add a link to call the above module but it isn't clear if this will accomplish what you need to do. Maybe you should be including this module instead. You don't call a session, it is just a facility that you can use to pass info between modules and keep info through a transaction sequence. If you provide a more complete explanation, someone may be able to help you.

Aaha o.k, apologies. The basic answer I'm after is 'how can I add a 'refresh capture' link'

I'm sure you've all seen them, the ones where you can change just the capture dynamically if the user can't read it.

The first link was just ideally how I wanted to do it, they're not linked. It was just an example I had of changing something on the page dynamically. Granted, this wasn't very well explained.

I just wondered if there was a way for me to have a ahref link like in the first example, but it refresh the captcha. If that makes sense?

maybe something like:

<a href="captcha.php?  //  something to refresh the captcha  //">Refresh</a>

The simplest way is to just have a form with a refresh button where the action is the same module (assuming that it generates a random captcha each time). If the user has entered any data, then you need to pass them as hidden variables so they aren't lost (or as session variables). This will cause the screen to be refreshed from the server. If you want to get fancier, you can investigate JQuery / Javascript captchas that have this refresh built in.

The simplest way is to just have a form with a refresh button where the action is the same module (assuming that it generates a random captcha each time). If the user has entered any data, then you need to pass them as hidden variables so they aren't lost (or as session variables). This will cause the screen to be refreshed from the server. If you want to get fancier, you can investigate JQuery / Javascript captchas that have this refresh built in.

Aaah yes, great idea, didn't think of that, thanks alot for all your help :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.