codeboy89 Posted November 4, 2009 Share Posted November 4, 2009 Here is my signup page below, how do I add the reCAPTCHA widget and what else needs to be done to make it work? I am new and confused, any help to stop spammers would be very appreciated. Thanks for all the help so far guys. <?php echo "<form method=\"post\" enctype=\"multipart/form-data\" action=\"register_script.php\"> <center><span class=\"bodymain\">User Signup</span></center> <table width=\"450\" align=\"center\"> <tr> <td class=\"bodyfont\">First Name:</td> <td><input type=\"text\" name=\"fname\" size=\"20\" class=\"border\" /></td> </tr> <tr> <td class=\"bodyfont\">Last Name:</td> <td><input type=\"text\" name=\"lname\" size=\"20\" class=\"border\" /></td> </tr> <tr> <td class=\"bodyfont\">E-mail:</td> <td><input type=\"text\" name=\"email\" size=\"20\" class=\"border\" /></td> </tr> <tr> <td class=\"bodyfont\" valign=\"top\">Username:<br /><br /></td> <td><input type=\"text\" name=\"username\" size=\"20\" class=\"border\" maxlength=\"20\" /> <br /><span class=\"bodyfont\">(Max. 20 characters)<br />No Special Characters eg. ()!@./+#$%* or Spaces!</span> </td> </tr> <tr> <td class=\"bodyfont\">Password:</td> <td><input type=\"password\" name=\"password\" size=\"20\" class=\"border\" maxlength=\"20\" /> </td> </tr> <tr> <td class=\"bodyfont\">Confirm Password:</td> <td><input type=\"password\" name=\"password2\" size=\"20\" class=\"border\" maxlength=\"20\" /> </td> </tr> </table> <center><p><input type=\"submit\" value=\"Register\" class=\"border\" /></p></center> <p> </p> </form>"; ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
gizmola Posted November 4, 2009 Share Posted November 4, 2009 Step 1: Go to recaptcha site, do the signup get your recaptcha keys Step 2: Go to this page and read it: http://recaptcha.net/plugins/php/ Step 3: In step #2 there's a php library you download, so do that and put it in the appropriate place Step 4: Test out your new recaptcha'd page(s). Step 5: Come back here with problems, when you have already done step 1-4. Good luck -- recaptcha is a great solution, and works very well in my experience. It's nice to know that it is also helping to correct books that have been scanned for the benefit of future generations. Quote Link to comment Share on other sites More sharing options...
codeboy89 Posted November 4, 2009 Author Share Posted November 4, 2009 I have done this, I am not sure what to do Here is the code from reCAPTCHA that should go into the code above, I know the action needs to go where they have echo "You got it!" but what needs to be done to make it register? require_once('recaptchalib.php'); $publickey = "..."; $privatekey = "..."; # the response from reCAPTCHA $resp = null; # the error code from reCAPTCHA, if any $error = null; # are we submitting the page? if ($_POST["submit"]) { $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); if ($resp->is_valid) { echo "You got it!"; # 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; } } echo recaptcha_get_html($publickey, $error); Quote Link to comment Share on other sites More sharing options...
gizmola Posted November 5, 2009 Share Posted November 5, 2009 There are 2 sections: In your form code above, add this code at the top: require_once('recaptchalib.php'); $publickey = "..."; // you got this from the signup page Then where you want the recapctha to appear, you echo it out .. echo recaptcha_get_html($publickey); In your register_script.php -- require_once('recaptchalib.php'); $privatekey = "..."; $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); if (!$resp->is_valid) { // Redisplay the form -- would be good to pass an error message header("Location: --- your form script url"); // Do this die in case they are trying to game the redirect die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." . "(reCAPTCHA said: " . $resp->error . ")"); } else { // Recaptcha was good -- go ahead and do whatever other processing you need } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.