michaellunsford Posted October 3, 2007 Share Posted October 3, 2007 Okay, first off let me say I've done this a few times already and had no trouble. Short version: the captcha code gets refreshed before it can be compared with the $_POST security code. When I submit a contact form I get the "no match" error, so I added to the error message the two fields being compared. Interestingly, the captcha field is the same on the image. If you're new to AndyB's captcha script, the way it works is the page is supposed to load an external image. That image is generated by a php file that opens a session and makes the captcha code, then writes it to an image. So, when the page loads, it should have the previously generated captcha code in the session variable before the page loads the new image (which would also change the captcha code). Any ideas? Home of AndyB's script: http://www.digitalmidget.com/php_noob/captcha.php <?php //This page is "included" in index.php (which calls session_start()) $showform=true; if (isset($_POST['validform'])) { // clean and check form inputs including the secure image code $name = trim(strip_tags($_POST['name'])); $email = trim(strip_tags($_POST['email'])); $comments = trim(strip_tags($_POST['comments'])); $secure = strtoupper(trim(strip_tags($_POST['secure']))); $match = $_SESSION['captcha']; // the code on the image // input error checking if ($name=="") { $err.= "Please provide your name<br/>"; } if (!$email) { $err.= "Please provide your email address<br>"; } if ($email) { if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) { $err.= $email. " is not a valid email address.<br/>"; } } if ($comments=="") { $err.= "Please provide comments<br/>"; } if (!$secure) { $err.= "No security code entered<br/>"; } if (($secure!=$match) && ($secure!="")) { $err.= "Security code mismatch<br/>Code was: ".$match."<br />You entered: ".$secure."<br />"; } if ($err=="") { // success - input passed all tests do { $var.=key($_POST).": ".current($_POST)."\n"; }while(next($_POST)); $var.=$_SERVER['REMOTE_ADDR']." ".date("h:i:sA T m-d-Y"); if((strpos($_POST['name'],"\r",1)) OR (strpos($_POST['name'],"\n",1)) OR (strpos($_POST['email'],"\r",1)) OR (strpos($_POST['email'],"\n",1)) or (strlen($_POST['email']>100)) OR (strlen($_POST['name']>100))) ; else mail($admin_email,$_SERVER['SERVER_NAME']." Contact Form","The following was received from the contact form located on ".$_SERVER['SERVER_NAME'].".\n\n".strip_tags($var)); echo "<br><br>Request from ".$_SERVER['REMOTE_ADDR']." was successfully sent at ".date("h:i:sA T").".\n"; $showform=false; } else { echo "<strong>Form Error(s)</strong><br/>"; echo nl2br($err)."<br/>"; } } if($showform) echo $myrow['content'].'<br> <form id="contactform" name="contactform" method="post" action="contactus.html"><table align="center"> <tr><td>Your Name</td><td><input type="hidden" name="validform" value="1"><input type="text" name="name" value="'.$_POST['name'].'"></td></tr> <tr><td>Your Email</td><td><input type="text" name="email" value="'.$_POST['email'].'"></td></tr> <tr><td>Telephone</td><td><input type="text" name="phone" value="'.$_POST['phone'].'"></td></tr> <tr><td>Comments</td><td><textarea name="comments" cols="20" rows="5">'.$_POST['comments'].'</textarea></td></tr> <tr><td>Security Key</td><td><input type="text" name="secure"> <div style="width:100px; height:50px; background:url(/captcha/captcha_image.php) center center;"> </div></td></tr> <tr><td colspan="2" style="text-align:center;"> <a href="javascript:document.forms[\'contactform\'].reset();" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage(\'reset_button\',\'\',\'images/buttons/Reset_over.jpg\',1)"> <img src="images/buttons/Reset.jpg" alt="Reset Button" name="reset_button" border="0"> </a><a href="javascript:document.forms[\'contactform\'].submit();" onMouseOut="MM_swapImgRestore();" onMouseOver="MM_swapImage(\'submit_button\',\'\',\'images/buttons/Submit_over.jpg\',1);"> <img src="images/buttons/Submit.jpg" border="0" alt="Submit Button" name="submit_button"></a> </td></tr> </table></form><br><br>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/71700-solved-trouble-with-andybs-captcha-script/ Share on other sites More sharing options...
michaellunsford Posted October 3, 2007 Author Share Posted October 3, 2007 using the captcha as the background of a DIV was causing the issue. Quote Link to comment https://forums.phpfreaks.com/topic/71700-solved-trouble-with-andybs-captcha-script/#findComment-361104 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.