PHP 尝试编译 reCAPTCHA 代码时出现语法错误?
PHP syntax Error when attempting to compile reCAPTCHA code?
我正在尝试在我的网站上创建一个 reCAPTCHA 人工验证框,但是我无法克服 php 代码中的一个错误。我敢肯定这很简单,我只是无法克服它。出于安全原因,我取出了我的网站和私钥。
我编译时的错误:
"FATAL ERROR syntax error, unexpected ';' on line number 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);
我正在尝试在我的网站上创建一个 reCAPTCHA 人工验证框,但是我无法克服 php 代码中的一个错误。我敢肯定这很简单,我只是无法克服它。出于安全原因,我取出了我的网站和私钥。
我编译时的错误:
"FATAL ERROR syntax error, unexpected ';' on line number 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);