Php google recaptcha警告:非法字符串偏移量';成功';
我第一次尝试实现google recaptcha时遇到了以下错误:Php google recaptcha警告:非法字符串偏移量';成功';,php,recaptcha,Php,Recaptcha,我第一次尝试实现google recaptcha时遇到了以下错误:警告:非法字符串偏移量“成功” 这是需要检查recaptcha是否有效的代码: $response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=MYSECRETCODEHERE&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']); if($re
警告:非法字符串偏移量“成功”
这是需要检查recaptcha是否有效的代码:
$response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=MYSECRETCODEHERE&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']);
if($response["success"] == false){
echo('spam');
}else{
echo('not spam');
}
感谢@maximkou为我的问题提供了答案,我不得不将
response[“success”]==false
更改为response==false
file\u get\u contents
返回string
,但您可以将其作为array
访问。请在使用前准备$response
。例如,如果响应是json
,则使用json\u decode