【发布时间】:2015-11-03 21:26:24
【问题描述】:
我正在尝试在我的网站上创建一个 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>
【问题讨论】:
-
第8行是哪一行?
-
而不是
if(isset($data->success) AND $data->success==true){试试if( property_exists( $data, 'success' ) && $data->success==true ){ -
@RamRaider OP 可以对他的代码进行各种改进,但这与他们当前的问题无关。
-
@Martin 第 8 行是... $data = json_decode($response);
-
看我的回答,@IsaacWorley 我很确定问题出在你的
file_get_contents字符串中