Jump to content

Recaptcha Not Working - Oh Poop


joecool308

Recommended Posts

As a test, just trying to get it to parse correctly from one page to that next right now. I'm using LOCALHOST as my domain currently (hopefully that's not the problem) . Anyway here's my code and then the error message:first: Is the php code supposed to be inside the form? When I do that I get a blank page, so I've been leaving it out as to show the ReCaptcha widget. <form method="post" action="wtf.php"> <input type="submit" name="submit" value="submit" /> </form><?php require_once('recaptchalib.php'); $publickey = "I put my pub. key here"; echo recaptcha_get_html($publickey); ?>My second page looks like:<?php require_once('recaptchalib.php'); $privatekey = "I put in my private key"; $resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]); if (!$resp->is_valid) { // What happens when the CAPTCHA was entered incorrectly die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." . "(reCAPTCHA said: " . $resp->error . ")"); } else { // Your code here to handle a successful verification } ?>And here is the error i get when that page (wtf.php page):Notice: Undefined index: recaptcha_challenge_field in C:\wamp\www\capture\wtf.php on line 6Notice: Undefined index: recaptcha_response_field in C:\wamp\www\capture\wtf.php on line 7The reCAPTCHA wasn't entered correctly. Go back and try it again.(reCAPTCHA said: incorrect-captcha-sol)So what is happening?!

Link to comment
Share on other sites

If I put it inside it does not show the ReCaptcha. It's just blank as in just shows the form but not the recptcha.

Link to comment
Share on other sites

Whoops, didn't read the whole post. Well, the code is definitely supposed to go inside the form - I wouldn't see why that would inhibit the page from displaying. Do you have a link to this page?

Link to comment
Share on other sites

Well ya it's the <form action="wtf.php" method="post">

Link to comment
Share on other sites

Sorry, I meant a URL for the page that contains the form, so we can see it. Otherwise, have you tried disabling your CSS?

Link to comment
Share on other sites

The url is http://localhost/capture/blabla.php with links to wtf.php via <form action="wtf.php" method="post">No CCS right now on my page.

Link to comment
Share on other sites

Do you have a public-facing address for your server?Try just having (with a properly-formed page):

<form method="post" action="wtf.php"><?phprequire_once('recaptchalib.php');$publickey = "I put my pub. key here";echo recaptcha_get_html($publickey);?><input type="submit" name="submit" value="submit" /></form>

Also, view the source - can you see the reCAPTCHA HTML, even if it doesn't appear on the page?

Link to comment
Share on other sites

I just want to say thank you for working with me. I know I/we will get through this somehow. It always finds a way of working it's way out. So this is the source code for the script as you wrote above. This makes reference to the (require_once('recaptchalib.php')) in the original code. This may be getting a bit messy at this point. I really wonder if it has something to do with using LOCALHOST though it does not seem to make sense to me why that would be. <form method="post" action="wtf.php"><script type="text/javascript" src="http://api.recaptcha.net/challenge?k=I put my pub. key here"></script> <noscript> <iframe src="http://api.recaptcha.net/noscript?k=I put my pub. key here" height="300" width="500" frameborder="0"></iframe><br/> <textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea> <input type="hidden" name="recaptcha_response_field" value="manual_challenge"/> </noscript><input type="submit" name="submit" value="submit" /></form>Again, my main issues is the line error codes I've been getting on like 6 or something (refer to first post on this thread) . They are undefined by me somehow??? Yikes I wish I were a super geek sometimes.

Link to comment
Share on other sites

Hey I got an idea!!!!This code works, but how can I get it to be two pages instead of all the code in this one page. Like having a form, entering the recaptcha, then having it validate on a second page and -if valid equals true- then -go ahead and enter the form data (to my database).So again this code works - how would a separate into two pages? (This example just makes ref. to itself and does not require a second <form action> page as you can see:<html> <body> <form action="" method="post"><?phprequire_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);?> <br/> <input type="submit" name="submit" value="submit" /> </form> </body></html>

Link to comment
Share on other sites

The reason the indexes were undefined in your OP is because you weren't including the reCAPTCHA in the form, so the reCAPTCHA values weren't being sent through. As to the code that "works", just separate out the submission logic and place it on a separate 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;}}

Link to comment
Share on other sites

Thank You. I got it to work. One question though: why does this fail to show the recaptcha widget info on it's own?<?phprequire_once('recaptchalib.php');$publickey = "blablabla"; echo recaptcha_get_html($publickey);?>How come I have to have it in a form? (else I get a blank page). Is it because the -require_once ('recaptchalib.php') - function/file refers to form driven data?

Link to comment
Share on other sites

I don't know - I haven't worked with reCAPTCHA much. It's probably because recaptcha_get_html() echoes some JS that then checks for proper placement, though.

Link to comment
Share on other sites

Ya I slept on this and gave it some thought. If your're not filling in any form data, then no reason to have the recaptcha. It must be built in security thing just in case by accident you put the recaptcha info on one of your other pages which has no form info. Though by quick glance, it's just looks like the <submit> form field is what validates it as true on the second page, it requires more to validate as true. There are a few ways to set this up of course, but my way seems to work fine. Thanks for the help-o

Link to comment
Share on other sites

Actually, if you think well, reCaptcha needs a form whatever it is used for... it sends data to the server, so it needs input fields, (usually hidden), and a form to send them. Especially if js is not enabled in the user's browser, so there i no ajax possible. I had a quick look through the source after rendering (I use a userscript) and there is two fields: challenge and response. (their names are actually different... somewhat longer and more descriptive).I have made a contact form generator including a reCaptcha because some friends needed it, so I had to look at that.

Link to comment
Share on other sites

  • 1 year later...

Hi Friends, I am Worked out a Simple Google Recaptcha in PHP ... For your Reference I copy - paste here: First for this we need a Key : 2 types of key Private and Public, in our code we need just public key. So when generate key make it as Global it help to use same in wide range of domains , any way all recaptcha will work in localhost without any problem. So you can get a Key from : Recaptcha Registration link and download the files , only one "recaptchalib.php" . To work a recaptcha please give it in a valid HTML ... (must need <html> etc.. tags!), so come to code index.php ------------

 <?php// call the lib..require_once('recaptchalib.php');# was there a reCAPTCHA response?if ($_POST["submit"]) {	$response = recaptcha_check_answer($privatekey,		$_SERVER["REMOTE_ADDR"],		$_POST["recaptcha_challenge_field"],		$_POST["recaptcha_response_field"]);		if ($response->is_valid) {				echo "Yes, that was correct!";		} else {				# set the error code so that we can display it		echo "Eh, That wasn't right. Try Again.";		}}?><html><head><title>Recaptcha TEST</title></head><body><form action="index.php" method="post"><?php //echo recaptcha_get_html($publickey, $error); ?><script type="text/javascript"	 src="http://www.google.com/recaptcha/api/challenge?k=publickey">  </script>  <noscript>	 <iframe src="http://www.google.com/recaptcha/api/noscript?k=publickey"		 height="300" width="500" frameborder="0"></iframe><br>	 <textarea name="recaptcha_challenge_field" rows="3" cols="40">	 </textarea>	 <input type="hidden" name="recaptcha_response_field"		 value="manual_challenge">  </noscript><input type="submit" value="submit" name="submit"/></form></body></html>

ok , wish it Help You .... Thankfully,Anes P.A :)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...