Sign In | Register Now About Bytes | Help | Site Map
Connecting Tech Pros Worldwide

How to exit to a web page upon successful 'Recaptcha' input

Question posted by: Linda Jimerson (Newbie) on May 9th, 2008 06:25 AM
Hello - Thanks for any help you can provide. Below is code I am using for "recaptcha" form validation. It works well EXCEPT that (instead of echoing 'You got it!') as shown below when the accurate words are entered, I want to exit to another web page. What is the php code that would replace echo "You got it!"; and instead exit to another web page? Thanks very much. linda jimerson
Expand|Select|Wrap|Line Numbers
  1. <form action="" method="post" > 
  2.  <?php
  3.  require_once('recaptchalib.php');
  4. $publickey = "6Le-0AEAAAAAAGV3Ln-w867BhcXcme3hvBBpyQy7";
  5. $privatekey = "6Le-0AEAAAAAAEYvsU9tKhDCaLC3wKhqaCDSvjQ_";
  6. $resp = null;
  7. $error = null;
  8. if ($_POST["submit"]) {
  9.   $resp = recaptcha_check_answer ($privatekey,
  10.           $_SERVER["REMOTE_ADDR"],
  11.            $_POST["recaptcha_challenge_field"],
  12.           $_POST["recaptcha_response_field"]);
  13.   if ($resp->is_valid) {
  14.     echo "You got it! ";
  15.   } else {
  16.     $error = $resp->error;
  17.   }
  18. }
  19. echo recaptcha_get_html($publickey, $error);
  20. ?&g t;
  21.  
  22.  <br/>
  23.     <input type="submit" name="submit" value="submit" />
  24.     </form>
TheServant's Avatar
TheServant
Needs Regular Fix
462 Posts
May 9th, 2008
06:44 AM
#2

Re: How to exit to a web page upon successful 'Recaptcha' input
Expand|Select|Wrap|Line Numbers
  1. echo ("<meta http-equiv=\"refresh\" content=\"2;url=http://yourwebsite.com\">");


Notice the \'s there so that it doesn't see them as the closing of the echo. That statement will mean that the page will wait for 2 seconds (you can change this to 0) before it is redirected to yourwebsite.com.

Also, use code tags as I have!

AND what's your form action?

Reply
Markus's Avatar
Markus
Moderator
2,217 Posts
May 9th, 2008
06:47 AM
#3

Re: How to exit to a web page upon successful 'Recaptcha' input
check out the header() functions.

Expand|Select|Wrap|Line Numbers
  1. header("Location: success_page.php");

Reply
Linda Jimerson's Avatar
Linda Jimerson
Newbie
13 Posts
May 10th, 2008
08:21 PM
#4

Re: How to exit to a web page upon successful 'Recaptcha' input
Quote:
Expand|Select|Wrap|Line Numbers
  1. echo ("<meta http-equiv=\"refresh\" content=\"2;url=http://yourwebsite.com\">");


Notice the \'s there so that it doesn't see them as the closing of the echo. That statement will mean that the page will wait for 2 seconds (you can change this to 0) before it is redirected to yourwebsite.com.

Also, use code tags as I have!

AND what's your form action?


THANK YOUR VERY MUCH. THIS WORKED. LINDA JIMERSON

Reply
hsriat's Avatar
hsriat
Expert
1,470 Posts
May 11th, 2008
05:27 PM
#5

Re: How to exit to a web page upon successful 'Recaptcha' input
Quote:
THANK YOUR VERY MUCH. THIS WORKED. LINDA JIMERSON

But still header("Location:target_page.php") is recommended.

Reply
TheServant's Avatar
TheServant
Needs Regular Fix
462 Posts
May 11th, 2008
10:08 PM
#6

Re: How to exit to a web page upon successful 'Recaptcha' input
Quote:
THANK YOUR VERY MUCH. THIS WORKED. LINDA JIMERSON


No Problem.

Quote:
But still header("Location:target_page.php") is recommended.


I agree, but this has to come before any html. To do it this way, and I agree it is a better way, you need your script to return a variable so that when the header comes up you can test for that variable and then use the location function. But doing exactly what the OP asked for, replacing the echo contents, meta's are easier.

Reply
Markus's Avatar
Markus
Moderator
2,217 Posts
May 12th, 2008
06:29 AM
#7

Re: How to exit to a web page upon successful 'Recaptcha' input
Quote:
No Problem.



I agree, but this has to come before any html. To do it this way, and I agree it is a better way, you need your script to return a variable so that when the header comes up you can test for that variable and then use the location function. But doing exactly what the OP asked for, replacing the echo contents, meta's are easier.


Not all browsers support them.

Reply
TheServant's Avatar
TheServant
Needs Regular Fix
462 Posts
May 13th, 2008
02:59 AM
#8

Re: How to exit to a web page upon successful 'Recaptcha' input
Quote:
Not all browsers support them.


Ahh touché! Listen to the pro's, I am but a humble hobbiest! However, I have not had a problem with meta yet.

Reply
dlite922's Avatar
dlite922
Site Addict
558 Posts
May 13th, 2008
05:02 AM
#9

Re: How to exit to a web page upon successful 'Recaptcha' input
Quote:
Ahh touché! Listen to the pro's, I am but a humble hobbiest! However, I have not had a problem with meta yet.


Believe us.

Correct me if I'm wrong, as I don't know, only you would. When you use meta instead of header, what happens when you click the back button? In IE, do you just end up back on the current page?

Expand|Select|Wrap|Line Numbers
  1. If($your_response)
  2. {
  3.     echo "That's a slight annoyance to users, but a  good way to keep them on the same page"; 
  4. }
  5. else
  6. {
  7.    echo "...hmmm...didn't know that.You learn something new everyday"; 
  8. }

Reply
hsriat's Avatar
hsriat
Expert
1,470 Posts
May 13th, 2008
08:24 AM
#10

Re: How to exit to a web page upon successful 'Recaptcha' input
Expand|Select|Wrap|Line Numbers
  1. die('Never used refresh meta, and never thought it this way.');

Reply
TheServant's Avatar
TheServant
Needs Regular Fix
462 Posts
May 13th, 2008
10:11 PM
#11

Re: How to exit to a web page upon successful 'Recaptcha' input
Quote:
Expand|Select|Wrap|Line Numbers
  1. die('Never used refresh meta, and never thought it this way.');


I still don't know how you guys get by the fact that you can only use header() before any html has been sent. There can be no delay (that I know of) which is sometimes required. I use header() 99% of the time, but meta in those areas which I need either a delay and/or show some html first. Solutions?

Reply
Reply
Not the answer you were looking for? Post your question . . .
189,846 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
Top PHP Forum Contributors