Browse files

Add support for passing challenge/response manually

This makes integrations into frameworks a bit easier. If no values are passed, then the values will be read from $_POST as before, so that there is no BC break. 

Not sure if I got your coding style right, feel free to correct as needed.
  • Loading branch information...
1 parent f4a0736 commit 7fbad0b2b79d2de5907a8763b9732f2a963d16b0 @flack flack committed Mar 14, 2013
Showing with 4 additions and 6 deletions.
  1. +4 −6 Package/Captcha/Captcha.php
View
10 Package/Captcha/Captcha.php
@@ -208,20 +208,18 @@ public function html()
/**
* Checks and validates user's response
*
+ * @param string $captcha_challenge Optional challenge string. If empty, value from $_POST will be used
+ * @param string $captcha_response Optional response string. If empty, value from $_POST will be used
* @throws Exception
* @return Response
*/
- public function check()
+ public function check($captcha_challenge = false, $captcha_response = false)
{
if (!$this->getPrivateKey()) {
throw new Exception('You must set private key provided by reCaptcha');
}
-
- $captcha_challenge = false;
- $captcha_response = false;
-
// Skip processing of empty data
- if (isset($_POST['recaptcha_challenge_field']) && isset($_POST['recaptcha_response_field'])) {
+ if ((strlen($captcha_challenge) == 0 || strlen($captcha_response) == 0) && isset($_POST['recaptcha_challenge_field']) && isset($_POST['recaptcha_response_field'])) {
$captcha_challenge = $_POST['recaptcha_challenge_field'];
$captcha_response = $_POST['recaptcha_response_field'];
}

0 comments on commit 7fbad0b

Please sign in to comment.