Captcha error

Hi, I have a form in which I’ve installed captcha. The form is good until I tested it in case someone types in the wrong captcha code. I expect the page to tell the user that the code is incorrect, go back and try it again, but instead it just goes through as if the user-code is correct. Any help would be so appreciated!

Here is the processor code:

<?php session_start(); ?> <?php /* Set e-mail recipient */ $myemail = "[email protected]"; /* Check all form inputs using check_input function */ $yourname = check_input($_POST['yourname'], "Your name"); $subject = check_input($_POST['subject'], "Subject"); $email = check_input($_POST['email']); $comments = check_input($_POST['comments'], "Write your comments"); /* If e-mail is not valid show error message */ if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email)) { show_error("E-mail address not valid"); } /* If URL is not valid set $website to empty */ if (!preg_match("/^(https?:\/\/+[\w\-]+\.[\w\-]+)/i", $website)) { $website = ''; } /* Let's prepare the message for the e-mail */ $message = "Hello! Your contact form has been submitted by: Name: $yourname E-mail: $email Comments: $comments End of message "; /* Send the message using mail() function */ mail($myemail, $subject, $message); /* Redirect visitor to the thank you page */ header('Location: thanks.html'); exit(); /* Functions we used */ function check_input($data, $problem='') { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); if ($problem && strlen($data) == 0) { show_error($problem); } return $data; } function show_error($myError) { ?>
<html>
<body>

<b>Please correct the following error:</b><br />
<?php echo $myError; ?>
<?php include_once $_SERVER['DOCUMENT_ROOT'] . '/securimage/securimage.php'; if ($securimage->check($_POST['captcha_code']) == false) { // the code was incorrect // you should handle the error so that the form processor doesn't continue // or you can use the following code if there is no validation or you do not know how echo "The security code entered was incorrect.

"; echo "Please go back and try again."; exit; } ?> <?php exit(); } ?>
</body>
</html>

Here is the url, if needed: http://www.oneisone.com/form/about.html

and here is the html:

Your Name:
Subject:
E-mail:

Tell us a little about what you'd like to do:

CAPTCHA Image [ Different Image ]

I’d say PHP is probably executed in the order it’s written. Follow your code pretending you are performing what is requested in the PHP. It isn’t until after the email is sent that you check to see if the captcha was correct, but by then it’s too late. You need to process the captcha form before you actually send the email.

Hope this helps.

Yes, it makes sense and I finally got it to work. THANKS!

Sponsor our Newsletter | Privacy Policy | Terms of Service