slpctrl Posted September 5, 2008 Share Posted September 5, 2008 Hi everyone, I have this PHP CAPTCHA here: Here is the file to create the image: <?php session_start(); $str1 = md5(microtime() * mktime()); $str = substr($str1,0,5); $captcha = imagecreatefrompng("./captcha.png"); $black = imagecolorallocate($captcha,0,0,0); imageline($captcha,rand(0,50),rand(0,100),rand(0,200),rand(0,200),$black); imageline($captcha,rand(0,50),rand(0,100),rand(0,200),rand(0,200),$black); imageline($captcha,rand(0,50),rand(0,100),rand(0,200),rand(0,200),$black); imageline($captcha,rand(0,50),rand(0,100),rand(0,200),rand(0,200),$black); imageline($captcha,rand(0,50),rand(0,100),rand(0,200),rand(0,200),$black); imageline($captcha,rand(0,50),rand(0,100),rand(0,200),rand(0,200),$black); imageline($captcha,rand(50,200),rand(0,100),rand(50,200),rand(80,200),$black); imageline($captcha,rand(50,250),rand(0,100),rand(0,200),rand(50,200),$black); imageline($captcha,rand(70,150),rand(0,100),rand(50,200),rand(0,200),$black); imageline($captcha,rand(20,150),rand(0,100),rand(20,150),rand(35,200),$black); imageline($captcha,rand(80,200),rand(0,100),rand(50,200),rand(85,200),$black); imageline($captcha,rand(0,50),rand(0,100),rand(0,200),rand(0,200),$black); imagestring($captcha,rand(1,5),rand(0,100),rand(0,50),$str,$black); $_SESSION['str'] = md5($str); header("Content-type: image/png"); imagepng($captcha); ?> And my HTML form with the script to check the user input to see if it was the text created in the image: <?php session_start(); echo <<<HTML <html> <head> <title>Captcha</title> </head> <body> <img src="captcha.php" border="0"> <form action="" method="post"> Enter the text from the image:<br><input type="text" name="code" /> <input type="submit" /> </form> </body> </html> HTML; if(!$_POST['code']) die(); else { if(md5($_POST['code']) != $_SESSION['str']) die("Error: Wrong code entered"); else echo("Correct!"); } ?> Alright, now in the form though I want a button to ONLY refresh the image, not the whole page. How would I go about doing this? Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted September 7, 2008 Share Posted September 7, 2008 <input type="button" name="refresh" id="refresh" value="Refresh Captcha" onclick="javascript: document.getElementById("captcha").location='captcha.php?rand='+Math.random();" /> Then just give you captcha.php image the id of "captcha". The ?rand= just makes it get a new image. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.