我目前正在創建一個聯繫人表單,並且表單需要完成一個驗證碼以減少垃圾郵件,我遵循了關於如何在我的代碼中使用驗證碼的教程,但每次都沒有工作,希望有人可以幫助這裏。任何幫助,將不勝感激。無法讓Google Captcha正常工作
HTML
<body>
<hgroup>
<h1>Contact Us</h1>
<?php if(isset($_GET['CaptchaPass'])){ ?>
<h3>Your message was sent, you should recieve an email back within 24
hours.</h3>
<?php } ?>
<?php if(isset($_GET['CaptchaFail'])){ ?>
<h3>Captcha Failed. Please try again!</h3>
<?php } ?>
</hgroup>
<form method='post' action='contactver.php'>
<div class="group">
<input type="text" name="name"><span class="highlight"></span><span
class="bar"></span>
<label>Name</label>
</div>
<div class="group">
<input type="email" name="email"><span class="highlight"></span><span
class="bar"></span>
<label>Email</label>
</div>
<div class="group">
<input type="phone" name="phone"><span class="highlight"></span><span
class="bar"></span>
<label>Phone No.</label>
</div>
<div class="group">
<input type="message" name="message"><span class="highlight"></span><span
class="bar"></span>
<label>Message</label>
</div>
<div class="g-recaptcha" data-
sitekey="My Key, want to keep private :)"></div>
<button type="submit" name="login" class="button buttonBlue">Submit Message
<div class="ripples buttonRipples"><span class="ripplesCircle"></span></div>
</button>
</form>
PHP
$firstname = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
if(isset($_POST['login'])) {
$url = 'https://www.google.com/recaptcha/api/siteverify';
$privatekey = "Want to keep this private :)";
$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) {
echo("Pass");
}else {
header('Location: contact.php?CaptchaFail=true');
echo("Fail");
}
}
我沒有看到在您的PHP中重定向到「?CaptchaPass」。 – tilz0R
@ tilz0R我沒有添加在這個抱歉,但它在那裏,沒有工作,任何其他修復? ( – Bailee
)爲什麼不檢查Google的'$ data'對象?如果你使用了'var_dump'或'print_r',你可能會看到響應。 – tilz0R