【发布时间】:2016-09-07 18:59:49
【问题描述】:
我正在使用 Google Recaptcha,我最终得到了这段代码。我的目标是让我已经在工作的 php 表单仅在验证码完成后提交。任何帮助将不胜感激。
<?php
if (isset($_POST['ContactButton'])) {
$url = 'https://www.google.com/recaptcha/api/siteverify';
$privatekey = "6LePayETAAAAANJze7opnV6bQEX-n02p4UdZ8xfF";
$response = file_get_contents($url . "?
secret=" . $privatekey . "&response" . $_POST['g-recaptcha-
response'] . "&remoteip=" . $_SERVER['REMOTE_ADDR']);
$data = json_decode($respose);
if (isset($data -> success) AND $data -> success == true) {
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$formcontent = " From: $name \n Phone: $phone \n Message: $message";
$recipient = "magicmacaroni@gmail.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
header('Location: contact-thank-you.html');
exit();
} else {
header('location: index.html?captchafail=True');
}
}
?>
【问题讨论】:
-
你能解释一下有什么问题吗?
标签: php html captcha recaptcha