reCAPTCHA

Code junkies hangout here

Moderators: ChrisThornett, LXF moderators

reCAPTCHA

Postby bobthebob1234 » Wed Jan 20, 2010 6:32 pm

I would like to add a captcha to a form I have (which sends emails...) However it works in IE (6) but not firefox (on ubuntu & winblows)...
here is some code
Code: Select all
 <form action="new.php" method="post" name="form">
<?php

require_once('recaptchalib.php');
$publickey = "(deleted)";
$privatekey = "(deleted) ";

# the response from reCAPTCHA
$resp = null;
# the error code from reCAPTCHA, if any
$error = null;

# are we submitting the page?
if ($_POST["submit"]) {
   $error_count=0;
   echo '
     <tr>
     <td colspan="2" class="errors">
   Checking
   </td>
   ';
  $resp = recaptcha_check_answer ($privatekey,
                                  $_SERVER["REMOTE_ADDR"],
                                  $_POST["recaptcha_challenge_field"],
                                  $_POST["recaptcha_response_field"]);

  if ($resp->is_valid) {
    echo "<tr><td colspan=\"2\" class=\"errors\">You got it!</td></tr>";
    # in a real application, you should send an email, create an account, etc
  } else {
    # set the error code so that we can display it. You could also use
    # die ("reCAPTCHA failed"), but using the error message is
    # more user friendly
    $error = $resp->error;
   $error_count++;
    echo '<tr><td colspan="2" class="errors">The captcha was incorrect. ' . $error . '</td></tr>';
  }
  if ($error_count > 0) {
      $s ="";
      if ($error_count > 1) {
         $s = "s";
      }
       echo "<tr><td colspan=\"2\" class=\"errors\">There was $error_count error$s. Please correct these and try again.</td></tr>";
   }
}
?>

and
Code: Select all
<fieldset><legend>Captcha</legend>
Please enter the two words below.
<?php
echo recaptcha_get_html($publickey);
?>
      </fieldset>


If i echo $_POST["recaptcha_challenge_field"], in firefox it is blank and in ie it has lots of random letters and hashs,etc

Any ideas why this would be, and how to fix it?

Thanks
For certain you have to be lost to find the places that can't be found. Elseways, everyone would know where it was
User avatar
bobthebob1234
LXF regular
 
Posts: 1369
Joined: Thu Jan 03, 2008 9:38 pm
Location: A hole in a field

Postby Dutch_Master » Wed Jan 20, 2010 7:10 pm

phpBB3 has a working Cotcha environment, why not 'nick' their code? ;)
Dutch_Master
LXF regular
 
Posts: 2438
Joined: Tue Mar 27, 2007 1:49 am

Postby ollie » Thu Jan 21, 2010 10:18 am

Dutch_Master wrote:phpBB3 has a working Cotcha environment, why not 'nick' their code? ;)


reCAPTCHA supply the code required for free - no need to "nick" the code because it is free.

I haven't had any problems with reCATCHA, I've just included the code at http://recaptcha.net/plugins/php/. Point "3" goes at the top of your page. You make the page containing the form a PHP page and the code at point "4" goes on your form processing page (also PHP).

Note: I have deleted the public and private keys from your code posting, you don't want to give the private one out :wink:
User avatar
ollie
Moderator
 
Posts: 2749
Joined: Mon Jul 25, 2005 11:26 am
Location: Bathurst NSW Australia

Postby bobthebob1234 » Thu Jan 21, 2010 6:22 pm

opps thanks.

I'll try coping and pasting that code (again...) (although i did use the example first...)
For certain you have to be lost to find the places that can't be found. Elseways, everyone would know where it was
User avatar
bobthebob1234
LXF regular
 
Posts: 1369
Joined: Thu Jan 03, 2008 9:38 pm
Location: A hole in a field

Postby Dutch_Master » Thu Jan 21, 2010 6:26 pm

ollie wrote:reCAPTCHA supply the code required for free - no need to "nick" the code because it is free.
Which is why I put it in ' marks :P
Dutch_Master
LXF regular
 
Posts: 2438
Joined: Tue Mar 27, 2007 1:49 am

Postby bobthebob1234 » Thu Jan 21, 2010 6:41 pm

Something else in the page must be breaking it. Have tried new code and still not work. However copied example code to new page it all is good.

I also regenerated the keys.
For certain you have to be lost to find the places that can't be found. Elseways, everyone would know where it was
User avatar
bobthebob1234
LXF regular
 
Posts: 1369
Joined: Thu Jan 03, 2008 9:38 pm
Location: A hole in a field

Postby bobthebob1234 » Thu Jan 21, 2010 7:05 pm

I think it doesn't like tables in tables. Got it to work now (for the moment!). Thanks to all.
For certain you have to be lost to find the places that can't be found. Elseways, everyone would know where it was
User avatar
bobthebob1234
LXF regular
 
Posts: 1369
Joined: Thu Jan 03, 2008 9:38 pm
Location: A hole in a field


Return to Programming

Who is online

Users browsing this forum: No registered users and 0 guests

cron