Customization - Redirecting to a page if incorrect if captcha is entered incorrectly - rather than displaying white page with "The reCAPTCHA wasn't entered correctly" message

1,595 views
Skip to first unread message

ADK_Ltd

unread,
Feb 22, 2010, 10:10:03 AM2/22/10
to reCAPTCHA
Everything is working fine with my captcha, but I dont like the fact
that it forwards to a blank page with the 1 line of text if someone
enters in the incorrect words.

How do I go about changing it to redirect to a page on my site if the
the captcha words are incorrect.

Im using the form method (Pub & Priv Keys Hidden).

In my html file I have the following:

<form action="contact.php" method="post" name="ContactForm">
<label>Name:
<input name="name" type="text" size="30" />
</label>
<label>Email:
<input name="email" type="text" size="41" />
</label><br /><br />
<label>Your Message:<br />
<textarea name="comments" cols="90" rows="5"></textarea>
</label><br /><br />
<script type="text/javascript"
src="http://api.recaptcha.net/challenge?k=MYPUBCODE">
</script>
<noscript>
<iframe src="http://api.recaptcha.net/noscript?k=MYPUBCODE"
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><br />
<input name="submit" type="Submit" value="Submit" />
<br />
</form>

In my PHP file, the following (related to recaptcha):

require_once('recaptchalib.php');
$privatekey = "MYPRIVCODE ";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);

if (!$resp->is_valid) {
die ("The reCAPTCHA wasn't entered correctly. Go back and try it
again." .
"(reCAPTCHA said: " . $resp->error . ")");
}

Using standard recaptchalib.php

---

So I think its something to do with

die ("The reCAPTCHA wasn't entered correctly. Go back and try it
again." .
"(reCAPTCHA said: " . $resp->error . ")");

I just need to figure how to make it forward to a page called "contact-
fail.html" rather than display the message

Any help greatly appreciated.

Paul Herring

unread,
Feb 22, 2010, 10:12:36 AM2/22/10
to reca...@googlegroups.com
On Mon, Feb 22, 2010 at 3:10 PM, ADK_Ltd <des...@adk.ltd.uk> wrote:
[...]

> So I think its something to do with
>
> die ("The reCAPTCHA wasn't entered correctly. Go back and try it
> again." .
>       "(reCAPTCHA said: " . $resp->error . ")");
>
> I just need to figure how to make it forward to a page called "contact-
> fail.html" rather than display the message

If you haven't printed anything by that point, you can use header():
<http://php.net/manual/en/function.header.php> instead of die();


--
PJH

http://shabbleland.myminicity.com/env
http://www.chavgangs.com/register.php?referer=9375

ADK_Ltd

unread,
Feb 22, 2010, 10:27:07 AM2/22/10
to reCAPTCHA
Many thanks, got it to work using


header("Location: http://www.example.com/"); /* Redirect browser */

/* Make sure that code below does not get executed when we redirect.
*/
exit;

Chris Poer

unread,
Feb 22, 2010, 10:54:18 AM2/22/10
to reca...@googlegroups.com

Add the following header line pointing to a error page:

if (!$resp->is_valid) {
header('Location:
http://www.mysite/error.php');
die();
}

Using standard recaptchalib.php

---

Any help greatly appreciated.

--
You received this message because you are subscribed to the Google Groups
"reCAPTCHA" group.
To post to this group, send email to reca...@googlegroups.com.
To unsubscribe from this group, send email to
recaptcha+...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/recaptcha?hl=en.

Reply all
Reply to author
Forward
0 new messages