表格提交没有验证码

时间:2017-06-09 07:00:18

标签: php forms recaptcha

我正在尝试在收到大量垃圾邮件的网站上实施google captcha v2。验证码正在显示和工作,但表格可以在不按验证码的情况下提交。我找了一些类似的问题,但找不到任何对我有帮助的问题。

这是谷歌的验证码V2

形式:

<form action="mailer.php" method="post" onsubmit="return FrontPage_Form1_Validator(this)" language="JavaScript" name="FrontPage_Form1" enctype="multipart/form-data">
<input type="text" class="col-md-13 col-xs-12 name" name='name' placeholder='Name *'/>
<input type="text" class="col-md-13 col-xs-12 Email" name='Email' placeholder='Email *'/>
<input type="text" class="col-md-12 col-xs-12 Subject" name='Subject' placeholder='Subject'/>
<textarea type="text" class="col-md-12 col-xs-12 Message" name='Message' placeholder='Message *'></textarea>
<br>

<div class="captcha_wrapper col-md-12" style="margin-bottom: 10px;">

    <div class="g-recaptcha" data-sitekey="6Ld-ryQUAAAAAJSKzJubdxYjigpiTfhk11e1P7o9">
    </div>

</div>

mailer.php:

if ($_SERVER['REQUEST_METHOD'] == "POST") {
foreach ($_POST as $key => $value) {
    $msg .= ucfirst ($key) ." : ". $value . "\n";
}
} 
else {

foreach ($_GET as $key => $value) {

    $msg .= ucfirst ($key) ." : ". $value . "\n";

} 
}

//captcha section

$response = $_POST["g-recaptcha-response"];


$url = 'https://www.google.com/recaptcha/api/siteverify';

$data = array(
    'secret' => '6Ld-ryQUAAAAALpIkTPN82doQhCFmiWrC14_UbYk',
    'response' => $_POST['g-recaptcha-response'];
);
$options = array(
    'http' => array (
        'method' => 'POST',
        'content' => http_build_query($data)
    )
);
$context  = stream_context_create($options);
$verify = file_get_contents($url, false, $context);
$captcha_success=json_decode($verify);

//end of captcha section

mail($to, $subject, $msg, $headers);

if ($forward == 1) {
header ("Location:$location"); 
}
else {
include("index.html");
header( 'Location: ' ) ;
} 

`

谢谢。任何帮助表示赞赏

我觉得我需要将验证码放在if(isset())

1 个答案:

答案 0 :(得分:0)

打印$ captcha_success值以检查$ captcha_success中的内容并了解如何管理响应。然后,您可以正确地重定向导航。

  

的var_dump($ captcha_success); //将值转储到网页   error_log(print_r($ captcha_success,true),0); //转储到php   apache error_log