3

So I'm trying to send a string of characters through ajax to a php script, here's the Ajax

function gVerify(){
    var response = $('#g-recaptcha-response').val();
    console.log(response);
    $.ajax({
        type: 'POST',
        url: 'recaptcha.php',
        data: { response: response},
        success: function(data) {
            if(data == 'true'){
                console.log("Success");
            } else{
                console.log(data);
            }
        }
    });
};

and the php

<?php
$ip = $_SERVER['REMOTE_ADDR'];
$response = $_POST['response'];

$url='https://www.google.com/recaptcha/api/siteverify';
$secret = '6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe';

$verifyCaptcha = file_get_contents($url."?secret=".$secret."&response=".$response."&remoteip=".$ip);
$captchaReply = json_decode($verifyCaptcha);

if(isset($captchaReply->success) AND $captchaReply->success == true){
    //Captcha successful
    return 1;
} else {
    //captcha failed
    echo json_encode($response);
}
?>

The problem is the php variable $response doesn't receive the post value if the value is too long. I tried sending alphanumeric strings manually and if I send 1000 chars, it doesn't receive, if I send 500 chars, the variable does receive the data and I get the result back in the console through console.log(data); so I know everything else works. So is there a size limitation to this somewhere?

1

3 Answers 3

2

there is post_max_size set in php.ini file

you need to increase that limit in this file.

see here : http://php.net/manual/en/ini.core.php

Sign up to request clarification or add additional context in comments.

1 Comment

To others as well: The default limit of sending data is 8M or 80million characters, I was just sending 900 or so, there's no way I was reaching the limits
1

The max size is configured in the server. If you use an .htaccess file you can modify the value by coding in the following:

#set max post size
php_value post_max_size 20M

Wala

Comments

1

Well I solved the problem by adding JSON.stringify() to the data I was sending. So the code now looks like this:

function gVerify(){
    var response = $('#g-recaptcha-response').val();
    $.ajax({
        type: 'POST',
        url: 'recaptcha.php',
        data: { response: JSON.stringify(response) },
        success: function(data) {
            if(data == 1){
                console.log("Success");
            } else{
                console.log(data);
            }
        }
    });
};

This added quotes around the token which I removed in php but at least I got the complete token.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.