I was pulling my hair out regarding this one for ages with the php version of recaptcha
I had everything in the right place, recaptchalib.php included, public private keys set, recaptcha_get_html inside the form. It should have worked. See code below:
<html>
<head></head>
<body>
<?php
require_once('recaptchalib.php');
$publickey="6LfBHssSAAAAAPxAqPSkddCIXcFIdrl2lrNxJ8da";
$privatekey="6LfBHssSAAAAACIz-CYPmFpm6sp81S-W-RXingPz";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if ($resp->is_valid)
{
echo "Thank you ";
}
else
{
echo "Invalid recaptcha response: " . $resp->error;
}
?>
<table border="0" width="400" align="center">
<form method="POST" action="">
<tr><td>Name: </td><td><input type="text" name="name"/></td></tr>
<tr><td> </td><td><?php echo recaptcha_get_html($publickey, null);?></td></tr>
<tr><td> </td><td><input type="submit" value="submit" name="submit"></td></tr>
</form>
</table>
</body>
</html>
When I submitted the form, no matter whether the code was correct or not I kept getting back incorrect-captcha-sol in $resp->error
Turned out in the end that the problem was very simple… I had the table tags outside the form tags instead of the other way around i.e.
<table> <form> <tr><td></td></tr> </form> </table>
instead of:
<form> <table> <tr><td></td></tr> </table> </form>
Once I changed to the latter, it began working fine.
Hope this helps someone out there!
