Jump to content

recaptcha problems


austin350s10

Recommended Posts

I am trying to use reCAPTCHA but I am running into some problems.

 

The code below is my mail handler program.

 

<?php
require_once('recaptchalib.php');
$privatekey = ".....";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if(!$resp->is_valid) {
header("location:captcha_error.html");
die();
}
?>
<?php


/*subject and email variables*/ 
   $emailSubject = 'OptOut';
   $webMaster = '[email protected]';

/*gathering data variables*/
   $emailField = $_POST['email'];
   

/*email field*/

   $body = <<<EOD
<br><hr><br>
<h2>Please remove this email address from our mailing list</h2>
<hr>
$email <br>
EOD;

/*email sender script*/
   $headers = "From: Website\r\n";
   $headers .= "Content-type: text/html\r\n";
   $success = mail($webMaster, $emailSubject, $body, $headers);
   
/*resultes*/

   $theResults = <<<EOD
<html>
<body>
Thank you
</body>
</html>
EOD;
echo "$theResults";

?>

 

The problem I am having is that when the user enters a wrong security code they are directed to a separate error page:  captcha_error.html.  The error page has a link on it that directs the user back to the form but when they go back to the form all the questions the user entered end up disappearing.

 

Is there a way I can make the error message appear on the same page as the form itself? Or a way the form can hold its values?

 

You can test the my web page http://www.affordablehomecare.org/functions/example-captcha.php

 

Thanks,

 

-Austin-

Link to comment
https://forums.phpfreaks.com/topic/160059-recaptcha-problems/
Share on other sites

Submit the form to itself to do the checking, or change this redirect:

if(!$resp->is_valid) {
header("location:captcha_error.html");
die();

 

As far as saving the values if you navigate OFF of the page, you'll need to either store them in a database until they return and reload them, or if the information doesn't need to be secure, you can pass it back through the URL and use a $_GET request.

Link to comment
https://forums.phpfreaks.com/topic/160059-recaptcha-problems/#findComment-844396
Share on other sites

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.