PHP - reCaptcha总是返回false

时间:2016-01-07 09:55:51

标签: php recaptcha

我的代码的第一部分:

<?php
$msg='';
if($_SERVER["REQUEST_METHOD"] == "POST")
{
$recaptcha=$_POST['g-recaptcha-response'];
  if(!empty($recaptcha))
  {
   include("getCurlData.php");
   $google_url="https://www.google.com/recaptcha/api/siteverify";
   $secret='Secret key removed';
   $ip=$_SERVER['REMOTE_ADDR'];
   $url=$google_url."?secret=".$secret."&response=".$recaptcha."&remoteip=".$ip;
   $res=getCurlData($url);
   $res= json_decode($res, true);

      if($res['success'])
      {

            $msg="ok";
      }
      else
      {
            $msg="ok2:";
      }

   }
   else
    {
     $msg="ERROR.1";
    }

}
else
{
 $msg="ERROR.2";
}

}
?>

第二个:

<form action="" method="post">
<center><div class="g-recaptcha" data-sitekey="Site key removed"></div></center>
<li><input type="submit" class="button" value="Jogar" /></li>
<p><?php echo $msg; ?></p>

getCurlData.php

<?php
function getCurlData($url)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.16) Gecko/20110319 Firefox/3.6.16");
$curlData = curl_exec($curl);
curl_close($curl);
return $curlData;
}
?>

始终使用包含&#34; 1&#34;的消息返回false在末尾。我无法看出我的错误在哪里。即使我做对了,reCaptcha也会返回false。

0 个答案:

没有答案