Skip to content

Commit

Permalink
Made recaptcha_check_answer() simpler for use.
Browse files Browse the repository at this point in the history
  • Loading branch information
puneetkay committed Aug 28, 2013
1 parent 3b69b52 commit e7d9bc9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ Check the REcaptcha with the following function when submitted.

Run this code:
<pre><code>
$this->recaptcha->recaptcha_check_answer();
</code></pre>
Or this, if you have changed fieldnames:
<pre><code>
$this->recaptcha->recaptcha_check_answer(
$_SERVER['REMOTE_ADDR'],
$this->input->post('recaptcha_challenge_field'),
Expand Down Expand Up @@ -99,7 +103,7 @@ class Login extends MY_Controller {
if ($this->input->post('username') !== FALSE && $this->input->post('password') !== FALSE)
{
//Call to recaptcha to get the data validation set within the class.
$this->recaptcha->recaptcha_check_answer($_SERVER['REMOTE_ADDR'],$this->input->post('recaptcha_challenge_field'),$this->input->post('recaptcha_response_field'));
$this->recaptcha->recaptcha_check_answer();

//Store the username and password for easier access
$username = $this->input->post('username');
Expand Down
12 changes: 11 additions & 1 deletion libraries/Recaptcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ class Recaptcha {
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*
* UPDATE HISTORY:
* 28.08.2013 - Made recaptcha_check_answer() function bit simpler on default
* fields as html is generated by recaptcha_get_html() function.
* Updated by - Puneet Kalra (https://github.com/puneetkay)
*/

/**
Expand Down Expand Up @@ -176,12 +182,16 @@ function recaptcha_get_html ($error = null, $use_ssl = false)
* @param array $extra_params an array of extra variables to post to the server
* @return ReCaptchaResponse
*/
function recaptcha_check_answer ($remoteip, $challenge, $response, $extra_params = array())
function recaptcha_check_answer ($remoteip = null, $challenge = null, $response = null, $extra_params = array())
{
if ($this->privkey == null || $this->privkey == '') {
die ("To use reCAPTCHA you must get an API key from <a href='https://www.google.com/recaptcha/admin/create'>https://www.google.com/recaptcha/admin/create</a>");
}

$remoteip = ($remoteip == null) ? $_SERVER['REMOTE_ADDR'] : $remoteip;
$challenge = ($challenge == null) ? $this->_ci->input->post('recaptcha_challenge_field') : $challenge;
$response = ($response == null) ? $this->_ci->input->post('recaptcha_response_field') : $response;

if ($remoteip == null || $remoteip == '') {
die ("For security reasons, you must pass the remote ip to reCAPTCHA");
}
Expand Down

0 comments on commit e7d9bc9

Please sign in to comment.