Google reCAPTCHA server端PHP的寫法(v2、v3)
v3版本 $msg = array(); $secret = 'your_secret_key'; $gRecaptchaResponse = isset($_POST['g-recaptcha-response']) ? $_POST['g-recaptcha-response'] : null; $ip = $_SERVER['REMOTE_ADDR']; $domainName = $_SERVER['HTTP_HOST']; include_once ("recaptcha/src/autoload.php"); $recaptcha = new \ReCaptcha\ReCaptcha($secret); $resp = $recaptcha->setExpectedHostname($domainName) ->setExpectedAction('homepage') ->setScoreThreshold(0.5) ->verify($gRecaptchaResponse, $ip); if ($resp->isSuccess()) { // $msg['ending']=$resp->toArray(); } else { $errors = $resp->getErrorCodes(); $msg['ending']='recaptchaFail'; $msg['recaptcha']=$errors; echo json_encode($msg); exit(); } 其中,autoload.php是 官方在github 給的檔案: /* An autoloader for ReCaptcha\Foo classes. This should be required() * by the user before attempting to in