我遇到了4天前已安装google recpatcha的问题。当时一切正常,但今天突然打开网站时,它突然停止工作并在json响应中显示NULL
。当我在本地主机中测试相同的代码时,它可以完美运行。我不知道背后的魔力是什么。
if(isset($_POST['g-recaptcha-response']))
{
$captcha = $_POST['g-recaptcha-response'];
$privatekey = 'PRIVATE-KEY';
$url = 'https://www.google.com/recaptcha/api/siteverify';
$data = array(
'secret' => $privatekey,
'response' => $captcha,
'remoteip' => $_SERVER['REMOTE_ADDR']
);
$curlConfig = array(
CURLOPT_URL => $url,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => $data
);
$ch = curl_init();
curl_setopt_array($ch, $curlConfig);
$response = curl_exec($ch);
curl_close($ch);
$jsonResponse = json_decode($response);
var_dump($jsonResponse); //showing NULL in live server but returns json object in localhost
}
我不知道本地主机和实时服务器背后的原因是什么。令人惊讶的是,当我将其安装在实时服务器上时,它运行得很好