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?

Whip
  • 1,891
  • 22
  • 43
  • Please refer this link :- http://stackoverflow.com/questions/17810063/jquery-ajax-post-huge-string-value/17810208#17810208 – Manish Jesani May 13 '16 at 06:57

3 Answers3

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

  • 1
    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 – Whip May 14 '16 at 06:57
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

Webeng
  • 7,050
  • 4
  • 31
  • 59
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.

Whip
  • 1,891
  • 22
  • 43