我试图在我的网站上创建一个reCAPTCHA人工验证框,但是我无法通过我的php代码中的错误。我相信这很简单,我就是过不去。出于安全考虑,我拿出了我的网站和私钥。
编译错误:
"FATAL ERROR语法错误,第8行出现意外';' "
这是我的代码,提前感谢:
<?php
if(isset($_POST['ContactButton'])){
$url = 'https://www.google.com/recaptcha/api/siteverify';
$privatekey = "--- My Private Key ---";
$response = file_get_contents($url."?secret=".$#privatekey."&response=".$_POST['g-recaptcha-response']."&remoteip=".$_SERVER['REMOTE_ADDR']);
$data = json_decode($response);
if(isset($data->success) AND $data->success==true){
////true - what happens when user is verified
header('Location: ExampleCaptcha.php?CaptchaPass=True');
}else{
////false - what happens when the user ISNT verified
header('Location: ExampleCaptcha.php?CaptchaFail=True');
}
}
?>
<html>
<head>
<title>index</title>
<script src='https://www.google.com/recaptcha/api.js'></script>
</head>
<body>
<form method='post' action='index.html'>
<input type='text' name='inp' /><br>
<div class="g-recaptcha" data-sitekey="--- My Site Key ---"></div><br>
<input type='submit' /><br>
</form>
</body>
</html>
您的错误在这里:file_get_contents($url."?secret=".$#privatekey.
在字符串中有一个哈希(注释)符号,看起来像是在错误的地方,(打字错误?)…但是你的弦看起来很乱。改善这一点。错误将自行解决。
移除你错误放置的#
。变量不能以符号开头。
…
$string = $url."?secret=".$#privatekey."&response=".$_POST['g-recaptcha-response']."&remoteip=".$_SERVER['REMOTE_ADDR'];
^^^^ //What's this? Remove '#'
$response = file_get_contents($string);