Skip to main content
370H55V
Inspiring
December 11, 2009
Answered

reCaptcha question

  • December 11, 2009
  • 1 reply
  • 1201 views

I maintain two sites for local businesses. The owners have both expressed displeasure at the "bot" generated spam they get in their domain mailboxes, so I signed up for a reCaptcha account to try and cut down on the spam.

Im just learning php (as in this afternoon)

I can get the reCaptcha widget to appear and it works, but when I go to add the validation code, it wipes out my CSS and I lose my submit and clear buttons. Also the default error message appears in the page.

Attached are what it looks like as an html form, what it looks like with the messed up php code, and the php file.

I am trying to work with this as embedded php rather using rel links to a separate php document. Is that wrong?

There isn't much on this at the reCaptcha site.

This topic has been closed for replies.
Correct answer David_Powers

So I can't "embed" the php for the captcha, doI understand that correctly?

I should put the captcha code in a separate php document and do a <link rel="captcha.php">  to it from the contact page?

I'm new to php so I'm just learning how it works with html.


The reCatpcha code that I highlighted needs to go inside the processing script. You cannot use <link>. It's an integral part of the processing. You would need to create a PHP form processing script yourself or use a ready-made one. There are plenty of scripts available, some secure, others not so.

Since I write my own scripts, I'm afraid I can't recommend a particular one, although my book "The Essential Guide to Dreamweaver CS4" has a secure generic processing script that can be easily plugged into a site, and should work in tandem with the reCaptcha.

1 reply

370H55V
370H55VAuthor
Inspiring
December 11, 2009

I figured out the CSS part. Changing the response for valid to "null" cleaned that up. Now everything is working but I need to set it up so an incorrect answer prevents the submit function from executing in the form.

David_Powers
Inspiring
December 11, 2009

I'm not familiar with reCaptcha, but the principle behind all CAPTCHA scripts is the same. It doesn't prevent the form from being submitted. All the verification takes place on the server. If the value submitted doesn't match the value generated by the CAPTCHA, it's up to your server-side script to intervene.

I have had a look at your page, and the problems are immediately obvious. First of all you are using a Perl script to process the form. Secondly, you have put the PHP verification script inside the page. This won't work. You need to change the processing script to a PHP one, and incorporate the reCaptcha verification script into the processing script. At the moment, you're trying to mix oil and water. It won't work.

The following code is meant to go at the top of a PHP form processing script to prevent the form from being processed if the wrong value is entered in the recaptcha_response_field:

<?php require_once('recaptchalib.php');
$privatekey = "****removed for security*******";
$resp = recaptcha_check_answer ($privatekey,
                                $_SERVER["REMOTE_ADDR"],
                                $_POST["recaptcha_challenge_field"],
                                $_POST["recaptcha_response_field"]);

if (!$resp->is_valid) {
  die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
       "(reCAPTCHA said: " . $resp->error . ")");
 
}?>

370H55V
370H55VAuthor
Inspiring
December 11, 2009

So I can't "embed" the php for the captcha, doI understand that correctly?

I should put the captcha code in a separate php document and do a <link rel="captcha.php">  to it from the contact page?

I'm new to php so I'm just learning how it works with html.