Jump to content

form with captcha security coding


kralspace

Recommended Posts

Hi all,

I've been trying to add a captcha script to a form, having it check the security image first of course, then email the contents of the form. It checks the image,  goes on and says "thank you, your message is......etc", but I can't get it to send the email.....if anyone can look thru it and see what I'm doing wrong. I'd really, really appreciate it, Thanks, Kathy
<?php
session_start();

if( isset($_POST['submit'])) {
   if( $_SESSION['security_code'] == $_POST['security_code'] && !empty($_SESSION['security_code'] ) ) {
     
  $editFormAction = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
  $editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}

if ((isset($HTTP_POST_VARS["send_mail"])) && ($HTTP_POST_VARS["send_mail"] == "form")) {

$message = "Thank you.\n";
$message .= "Your entries were as follows -\n";
$message .= "

Name: $name
Email: $email
Comments: $comment";

$to = "[email protected]";
    $subject = "Comments on materials: $name";
             mail($to, $subject, $message, "From: OP-TEC <[email protected]>\r\n");

header("Location: http://www.op-tec.org/comment2.php");

}
   
  echo 'Thank you. Your message said "'.$_POST['message'].'"';
   } else {
     
  echo 'Sorry, you have provided an invalid security code';
   }
} else {
?>
<form action="form.php" method="post">
<label for="name">Name: </label><input type="text" name="name" id="name" /><br />
<label for="email">Email: </label><input type="text" name="email" id="email" /><br />
<label for="comment">Message: </label><textarea rows="5" cols="30" name="message" id="message"></textarea><br />
<img src="CaptchaSecurityImages.php?width=100&height=40&characters=5" /><br />
<label for="security_code">Security Code: </label><input id="security_code" name="security_code" type="text" /><br />
<input type="submit" name="submit" value="Submit" />
</form>

<?php
}
?>
Link to comment
https://forums.phpfreaks.com/topic/35272-form-with-captcha-security-coding/
Share on other sites

sorry for the previous coding, I used the wrong setting to insert the code, maybe this will read easier.....Kathy

[code]
<?php
session_start();

if( isset($_POST['submit'])) {
   if( $_SESSION['security_code'] == $_POST['security_code'] && !empty($_SESSION['security_code'] ) ) {
     
   
     $editFormAction = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
  $editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}

if ((isset($HTTP_POST_VARS["send_mail"])) && ($HTTP_POST_VARS["send_mail"] == "form")) {


$message = "Thank you.\n";
$message .= "Your entries were as follows -\n";

$message .= "

Name: $name
Email: $email
Comments: $comment";

   $to = "[email protected]";

      $subject = "Comments on materials: $name";

     mail($to, $subject, $message, "From: OP-TEC <[email protected]>\r\n");

header("Location: http://www.op-tec.org/comment2.php");

}      
     echo 'Thank you. Your message said "'.$_POST['message'].'"';
   } else {
      // Insert your code for showing an error message here
     echo 'Sorry, you have provided an invalid security code';
   }
} else {
?>

   <form action="form.php" method="post">
      <label for="name">Name: </label><input type="text" name="name" id="name" />

      <label for="email">Email: </label><input type="text" name="email" id="email" />

      <label for="comment">Message: </label><textarea rows="5" cols="30" name="message" id="message"></textarea>

      <img src="CaptchaSecurityImages.php?width=100&height=40&characters=5" />

      <label for="security_code">Security Code: </label><input id="security_code" name="security_code" type="text" />

      <input type="submit" name="submit" value="Submit" />
   </form>

<?php
   }
?>
[/code]

the url for the form is: http://www.op-tec.org/kathy/formtest.php

-onward thru the fog!
  • 1 month later...
I'm trying to use this form on my localhost along with the Captcha PHP.  However, the $_SESSION[security_code] is always empty prior to doing the check.  It always fails.  But if I test it on your URL, it works.  Some config must be wrong on my system.  ANy ideas?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.