PHP没有';如果字符串太长,则无法接收POST
因此,我试图通过ajax将字符串发送到php脚本,以下是ajaxPHP没有';如果字符串太长,则无法接收POST,php,ajax,Php,Ajax,因此,我试图通过ajax将字符串发送到php脚本,以下是ajax function gVerify(){ var response = $('#g-recaptcha-response').val(); console.log(response); $.ajax({ type: 'POST', url: 'recaptcha.php', data: { response: response}, success
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);
}
}
});
};
还有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);
}
?>
问题是,如果值太长,php变量
$response
不会收到post值。我尝试手动发送字母数字字符串,如果我发送1000个字符,它不会接收,如果我发送500个字符,变量会接收数据,我通过console.log(data)将结果返回控制台代码>所以我知道其他一切都是有效的。那么,在某个地方有大小限制吗?php.ini文件中设置了post\u max\u大小
您需要增加此文件中的限制
请参见此处:最大大小在服务器中配置。如果使用.htaccess
文件,可以通过以下方式编码来修改该值:
#set max post size
php_value post_max_size 20M
Wala我通过向发送的数据添加JSON.stringify()
解决了这个问题。因此,代码现在如下所示:
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);
}
}
});
};
这在我在php中删除的令牌周围添加了引号,但至少我得到了完整的令牌。请参考此链接:-也参考其他链接:发送数据的默认限制为800万或8000万个字符,我只发送了900个左右,我不可能达到限制