Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP doesn't receive POST if string is too long

Tags:

ajax

php

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?

like image 647
Whip Avatar asked Apr 02 '26 09:04

Whip


2 Answers

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

like image 185
Megha Patel Avatar answered Apr 03 '26 21:04

Megha Patel


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

like image 44
Webeng Avatar answered Apr 03 '26 21:04

Webeng



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!