Linux Format forums Forum Index Linux Format forums
Help, discussion, magazine feedback and more
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

reCAPTCHA

 
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming
View previous topic :: View next topic  
Author Message
bobthebob1234
LXF regular


Joined: Thu Jan 03, 2008 9:38 pm
Posts: 1368
Location: A hole in a field

PostPosted: Wed Jan 20, 2010 6:32 pm    Post subject: reCAPTCHA Reply with quote

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:

 <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:

<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
Back to top
View user's profile Send private message
Dutch_Master
LXF regular


Joined: Tue Mar 27, 2007 2:49 am
Posts: 2422

PostPosted: Wed Jan 20, 2010 7:10 pm    Post subject: Reply with quote

phpBB3 has a working Cotcha environment, why not 'nick' their code? Wink
Back to top
View user's profile Send private message
ollie
Moderator


Joined: Mon Jul 25, 2005 12:26 pm
Posts: 2749
Location: Bathurst NSW Australia

PostPosted: Thu Jan 21, 2010 10:18 am    Post subject: Reply with quote

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


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
Back to top
View user's profile Send private message
bobthebob1234
LXF regular


Joined: Thu Jan 03, 2008 9:38 pm
Posts: 1368
Location: A hole in a field

PostPosted: Thu Jan 21, 2010 6:22 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Dutch_Master
LXF regular


Joined: Tue Mar 27, 2007 2:49 am
Posts: 2422

PostPosted: Thu Jan 21, 2010 6:26 pm    Post subject: Reply with quote

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 Razz
Back to top
View user's profile Send private message
bobthebob1234
LXF regular


Joined: Thu Jan 03, 2008 9:38 pm
Posts: 1368
Location: A hole in a field

PostPosted: Thu Jan 21, 2010 6:41 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
bobthebob1234
LXF regular


Joined: Thu Jan 03, 2008 9:38 pm
Posts: 1368
Location: A hole in a field

PostPosted: Thu Jan 21, 2010 7:05 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
View previous topic :: View next topic  
Display posts from previous:   
Post new topic   Reply to topic    Linux Format forums Forum Index -> Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Linux Format forums topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group


Copyright 2011 Future Publishing, all rights reserved.


Web hosting by UKFast