darkfreaks Posted August 29, 2007 Share Posted August 29, 2007 hey guys im trying to implement captcha with my guestbook i just need abit of help making the code work right. the image wont appear all i get is a red x? <?php session_start(); //Encrypt the posted code field and then compare with the stored key if(md5($_POST['key']) != $_SESSION['key']) { die("Error: You must enter the code correctly"); } }else{ $sql="INSERT INTO guestbook(name, email, comment, datetime)VALUES('$name', '$email', '$comment', '$datetime')"; $result=mysql_query($sql); mysql_close(); } ?> and the form code <tr><td valign="center"><img xsrc='captcha.php' border="0"> </td></tr> <tr> <td valign="center"><input name="key" type="text" id="key" size="40" /></td></tr> Quote Link to comment https://forums.phpfreaks.com/topic/67161-hep-with-captcha/ Share on other sites More sharing options...
darkfreaks Posted August 29, 2007 Author Share Posted August 29, 2007 hmmm still Getting the Red X? could it be my captcha file? Quote Link to comment https://forums.phpfreaks.com/topic/67161-hep-with-captcha/#findComment-336819 Share on other sites More sharing options...
Fadion Posted August 29, 2007 Share Posted August 29, 2007 lol, noone could have helped as there is not captcha code in here . Anyway solve this as marked if u dont have any other question. Quote Link to comment https://forums.phpfreaks.com/topic/67161-hep-with-captcha/#findComment-336822 Share on other sites More sharing options...
darkfreaks Posted August 29, 2007 Author Share Posted August 29, 2007 My Captcha Code: <?php //Start the session so we can store what the code actually is. session_start(); //Now lets use md5 to generate a totally random string $md5 = md5(microtime() * mktime()); /* We dont need a 32 character long string so we trim it down to 5 */ $string = substr($md5,0,5); /* Now for the GD stuff, for ease of use lets create the image from a background image. */ $captcha = imagecreatefrompng("./captcha.png"); /* Lets set the colours, the colour $line is used to generate lines. Using a blue misty colours. The colour codes are in RGB */ $black = imagecolorallocate($captcha, 0, 0, 0); $line = imagecolorallocate($captcha,233,239,239); /* Now to make it a little bit harder for any bots to break, assuming they can break it so far. Lets add some lines in (static lines) to attempt to make the bots life a little harder */ imageline($captcha,0,0,39,29,$line); imageline($captcha,40,0,64,29,$line); /* Now for the all important writing of the randomly generated string to the image. */ imagestring($captcha, 5, 20, 10, $string, $black); /* Encrypt and store the key inside of a session */ $_SESSION['key'] = md5($string); /* Output the image */ header("Content-type: image/png"); imagepng($captcha); ?> Quote Link to comment https://forums.phpfreaks.com/topic/67161-hep-with-captcha/#findComment-336824 Share on other sites More sharing options...
Fadion Posted August 29, 2007 Share Posted August 29, 2007 Didnt notice u wrote about the red x. The source of the image should be src and not xsrc: <img src='captcha.php' border="0"> Quote Link to comment https://forums.phpfreaks.com/topic/67161-hep-with-captcha/#findComment-336828 Share on other sites More sharing options...
Fadion Posted August 29, 2007 Share Posted August 29, 2007 Or if that doesnt work, try changing: this imagecreatefrompng("./captcha.png"); to: imagecreatefrompng("captcha.png"); Quote Link to comment https://forums.phpfreaks.com/topic/67161-hep-with-captcha/#findComment-336830 Share on other sites More sharing options...
darkfreaks Posted August 29, 2007 Author Share Posted August 29, 2007 i did both is still isnt showing up :-X Quote Link to comment https://forums.phpfreaks.com/topic/67161-hep-with-captcha/#findComment-336834 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.