Jump to content

PHP and ReCaptcha


Foosicle

Recommended Posts

 <table>
       <tbody bgcolor="#EFEFF5">
       <form name="helpform" method="post" action="">
        <div id="recaptcha">
	<?php require_once('include/recaptchalib.php');
  $publickey = "**************************** "; // you got this from the signup page
  echo recaptcha_get_html($publickey); 
  		?>
        </div>
          <tr id="contactform">
              <td>Your Email: </td>
              <td>
                	<input name="FROM" type="text" size="40" maxlength="30" value="<?php echo stripslashes(trim(htmlentities($FROM))) ?>" onFocus="this.value==this.defaultValue?this.value='':null">
              </td>
              </tr>
          <tr id="contactform">
              <td>First Name: </td>
              <td>
                	<input name="fname" type="text" size="40" maxlength="20" value="<?php echo stripslashes(trim(htmlentities($fname)))?>" onFocus="this.value==this.defaultValue?this.value='':null">
              </td>
          </tr>
          <tr id="contactform">
              <td>Last Name: </td>
              <td>
                	<input name="lname" type="text" size="40" maxlength="20" value="<?php echo stripslashes(trim(htmlentities($lname)))?>" onFocus="this.value==this.defaultValue?this.value='':null">
              </td>
          </tr>
          <tr id="contactform">
              <td>Message: </td>
              <td>
            	<textarea name="message" rows="5" cols="31" maxlength="200" value="<?php echo stripslashes(trim(htmlentities($message)))?>" wrap="physical"></textarea>
              </td>
          </tr>
              </tr>
          <tr>
          		<td>
                <input type="submit" value="Submit" action="mail()">
                </td>
          </tr>
          
          </form>

Link to comment
https://forums.phpfreaks.com/topic/240315-php-and-recaptcha/#findComment-1234422
Share on other sites

here comes the error ;)

 

my verify file looks like:

<?php
	 $errors = array();

 //READ the user recaptcha
 require_once('recaptchalib.php');
 $privatekey = "******************************";
 $resp = recaptcha_check_answer ($privatekey,
								 $_SERVER["REMOTE_ADDR"],
								 $_POST["recaptcha_challenge_field"],
								 $_POST["recaptcha_response_field"]);

 //READ the posted form data
 $fromemail = $_POST['fromemail'];
 $fname = $_POST['fname'];
 $lname = $_POST['lname'];
 $message = $_POST['message'];

 //VALIDATE form data exists
     if(!isset($frommail) ||
        !isset($fname) ||
        !isset($lname) ||
        !isset($message)){
	echo 'We are sorry, but there appears to be a problem with the form you submitted.';      
     }else{
	echo 'success';
	}

	$fromemail = stripslashes($fromemail);
	$fname = stripslashes($fname);
	$lname= stripslashes($lname);
	$message = stripslashes($message);

	$fromemail = trim(htmlentities($fromemail));
	$fname = trim(htmlentities($fname));
	$lname= trim(htmlentities($lname));
	$message = trim(htmlentities($message));

	//VALIDATE !errors
  if (!empty($errors)){
	redirect_to("http://www.*******.com/index.php");	
	}

	//CREATE the email form data
	$to = "customerservice@*******.com"; 
	$subject = $fname . " " . $lname;
	$headers = "From: " . $fromemail;


  if (!$resp) {
	   // What happens when the CAPTCHA was entered incorrectly
	   echo ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
			"(reCAPTCHA said: " . $resp->error . ")");
  }else {
   // Your code here to handle a successful verification
   echo "SUCCESS!";
  }


	mail($to, $subject, $message, $headers);

?>

Link to comment
https://forums.phpfreaks.com/topic/240315-php-and-recaptcha/#findComment-1234472
Share on other sites

//VALIDATE form data exists

   

 if(!isset($frommail) ||
        !isset($fname) ||
        !isset($lname) ||
        !isset($message)){
	echo 'We are sorry, but there appears to be a problem with the form you submitted.';      
     }else{
	echo 'success';
	}

 

This gives me err.

'We are sorry, but there appears to be a problem with the form you submitted.'

Link to comment
https://forums.phpfreaks.com/topic/240315-php-and-recaptcha/#findComment-1234473
Share on other sites

In an effort to validate safe data I have attempted to implement stripslashes, trim, and htmlentities...

How does that code look?

               

                $fromemail = stripslashes($fromemail);

$fname = stripslashes($fname);

$lname= stripslashes($lname);

$message = stripslashes($message);

 

$fromemail = trim(htmlentities($fromemail));

$fname = trim(htmlentities($fname));

$lname= trim(htmlentities($lname));

$message = trim(htmlentities($message));

Link to comment
https://forums.phpfreaks.com/topic/240315-php-and-recaptcha/#findComment-1234483
Share on other sites

$recaptcha_challenge_field = $_POST["recaptcha_challenge_field"];

$recaptcha_response_field = $_POST["recaptcha_response_field"];

 

echo $recaptcha_challenge_field;

echo $recaptcha_response_field;

 

so according to this.. they are not getting posted.

strange because I have no way of seeing the code in the form other than :

           

            <?php

            require_once('include/recaptchalib.php');

              $publickey = "************************-******* ";

            // you got this from the signup page

              echo recaptcha_get_html($publickey);

              ?>

 

So if that is not displaying anything.. should i worry? and how?

 

 

Link to comment
https://forums.phpfreaks.com/topic/240315-php-and-recaptcha/#findComment-1234554
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.