darkfreaks Posted August 30, 2007 Share Posted August 30, 2007 Hey im trying to figure out why it wont write the numbers to the captcha image here is the 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); ?> Form code <tr><td valign="center"><img src="http://www.wiccan-gathering.com/lilysgraveyard/addons/Guestbook/captcha.png" border="0"> </td></tr> <tr> <td valign="center"><input name="code" type="text" id="code" size="10" /></td></tr> Quote Link to comment Share on other sites More sharing options...
Jessica Posted August 30, 2007 Share Posted August 30, 2007 It's hard to do error reporting with images. Try commenting out this line: header("Content-type: image/png"); This will let you see if any errors show up. If not, try simplifying it by seeing if you can get it to print "hi". Then see if you can get it to print a random number. It's possible the problem is with your md5() section, I don't know. Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted August 30, 2007 Author Share Posted August 30, 2007 i tried replacing the ("captcha.png"); line with the actual adress i got random code all down the page? Quote Link to comment Share on other sites More sharing options...
Jessica Posted August 30, 2007 Share Posted August 30, 2007 What? That wasn't quite what I suggested... Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted August 30, 2007 Author Share Posted August 30, 2007 anyway i dont get any errors when i comment out that line *shrug* the image wont show up unless i put the actual adress to the image in the image tag in the form. Quote Link to comment Share on other sites More sharing options...
Jessica Posted August 30, 2007 Share Posted August 30, 2007 So no errors, try my next suggestion: Change this line: imagestring($captcha, 5, 20, 10, $string, $black); To: imagestring($captcha, 5, 20, 10, 'hi', $black); Does it print the "hi" in the image? Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted August 30, 2007 Author Share Posted August 30, 2007 lol it works look http://www.wiccan-gathering.com/lilysgraveyard/addons/Guestbook/guestbook.php any suggestions at to whats wrong? Quote Link to comment Share on other sites More sharing options...
Jessica Posted August 30, 2007 Share Posted August 30, 2007 What? That doesn't make any sense. What file? If you change a line of code in your captcha image why would it affect your form? Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted August 30, 2007 Author Share Posted August 30, 2007 it works whatever you had me put in. so i dont get why it didnt originally show? Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted August 30, 2007 Author Share Posted August 30, 2007 this is so odd it wont show in the cart script but it show when i directly link it? Quote Link to comment Share on other sites More sharing options...
Jessica Posted August 30, 2007 Share Posted August 30, 2007 Oh. Your HTML links to the image, not to the PHP file. Change <img src="http://www.wiccan-gathering.com/lilysgraveyard/addons/Guestbook/captcha.png" border="0"> to: <img src="http://www.wiccan-gathering.com/lilysgraveyard/addons/Guestbook/guestbook.php" border="0"> You'll probably want to add a random number on the end to avoid caching. Such as http://www.wiccan-gathering.com/lilysgraveyard/addons/Guestbook/guestbook.php?t=<?php print time(); ?> Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted August 30, 2007 Author Share Posted August 30, 2007 well i changed it to link to captcha.php like it originally was Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted August 30, 2007 Author Share Posted August 30, 2007 <img src="captcha.php" border="0"> Quote Link to comment Share on other sites More sharing options...
Jessica Posted August 30, 2007 Share Posted August 30, 2007 And the problem is? It works there. Did you add the timestamp like I said? Browsers will cache the image and so you'll only see an old version of it. This has been addressed a lot, I even posted about it this week. Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted August 30, 2007 Author Share Posted August 30, 2007 it works when i link it directly yes , but when i look at it here http://www.lilysgraveyard.com/index.php?dir=addons/Guestbook&page=guestbook it does not work. Quote Link to comment Share on other sites More sharing options...
Jessica Posted August 30, 2007 Share Posted August 30, 2007 I'm not going to keep saying it over and over again. <img src="captcha.php" border="0"> OBVIOUSLY is a broken image. This is the last time I will write it out: Your image is at: http://www.wiccan-gathering.com/lilysgraveyard/addons/Guestbook/captcha.php So the HTML must be something like this: <img src="http://www.wiccan-gathering.com/lilysgraveyard/addons/Guestbook/guestbook.php" border="0"> Since it's in the Guestbook folder. Also, you'll want to add a random number such as the time. <img src="http://www.wiccan-gathering.com/lilysgraveyard/addons/Guestbook/guestbook.php?t=<?php print time(); ?>" border="0"> Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted August 30, 2007 Author Share Posted August 30, 2007 thanks so much im sorry if im abit slow. im not much with image stuff. anyways one minor thing before i press solve topic, it isnt verifying whether its right or not im assuming that would be the if statements? <?php //Encrypt the posted code field and then compare with the stored key if(md5($_POST['code']) != $_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(); } ?> Quote Link to comment Share on other sites More sharing options...
Jessica Posted August 30, 2007 Share Posted August 30, 2007 looks fine, we'd have to see more of the form code. Does your code have session_start() on every page? Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted August 30, 2007 Author Share Posted August 30, 2007 well what it does is error "Errror: you have an incorrect code" before you even hit submit. i want it to display after it submits if it finds an incorrect code and yes i have session_start on the page. Quote Link to comment Share on other sites More sharing options...
Jessica Posted August 30, 2007 Share Posted August 30, 2007 Try this: if(isset($_POST['submit'])){ if(md5($_POST['code']) != $_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); } } Assuming your submit button is named "submit" - if not, change that to whatever it is. 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.