我在google验证验证码中收到邮件设置错误

时间:2017-02-09 12:13:37

标签: php

<?php 
java_session('remote_ip', $_SERVER['REMOTE_ADDR']);

以下是php

<!DOCTYPE html>
<html>
    <head>
        <title>
            Google Captcha Form With Send Mail
        </title>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
        <link rel="stylesheet" type="text/css" href="css/bootstrap-theme.min.css">
        <link rel="stylesheet" type="text/css" href="css/style.css">
    </head>
    <body>
        <form id="contactform" action="action.php" method="post" class="form" role="form">
            <div class="form-group">
                <div class="row">
                    <div class="col-lg-3">
                        <label>Name:</label>
                    </div>
                    <div class="col-lg-5">
                        <input class="form-control required" id="vname" name="vname" placeholder="Your Name" type="text" required />
                    </div>
                </div>
            </div>
            <br>
            <div class="form-group">
                <div class="row">
                    <div class="col-lg-3">
                        <label>Email:</label>
                    </div>
                    <div class="col-lg-5">
                        <input class="form-control required" id="vemail" name="vemail" placeholder="Your Email" type="email" required />
                    </div>
                </div>
            </div>
            <br>
            <div class="form-group">
                <div class="row">
                    <div class="col-lg-3">
                        <label>Information:</label>
                    </div>
                    <div class="col-lg-5">
                        <textarea type="text" name="msg" id="msg" rows="5" cols="50" class="form-control"></textarea>
                    </div>
                </div>
            </div>
            <br>
            <div class="form-group">
                <div class="row">
                    <div class="col-lg-3">
                        <label>Verify Whether Human</label>
                    </div>
                    <div class="col-lg-5">
                        <div class="g-recaptcha" data-sitekey="PRIVATE" class="form-control">
                        </div>
                    </div>
                </div>
            </div>
            <br>
            <div class="form-group">
                <input type="submit" class="btn btn-success form-send" value="Send">
            </div>
        </form>
        <script src="js/jquery.min.js"></script>
        <script src="js/recaptcha.js"></script>
        <script src="js/bootstrap.min.js"></script>
    </body>
</html>
  

注意:使用未定义的常数成功 - 假设成功&#39;在   第6行的C:\ xampp \ htdocs \ captchaform \ action.php

我得到这个错误帮助我这个我用trson解码没有帮助所以我在哪里错误

2 个答案:

答案 0 :(得分:3)

$ response有你无法使用的JSON数据和PHP。运算符来获取其密钥。   - 转换为数组   - 访问密钥

因为您的回答是这样的

{ "success": true, "challenge_ts": "2017-02-09T12:18:22Z", "hostname": "localhost" }

做这样的事情:

$response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret='PRIVATE'&response=" . $captcha . '&remoteip=' . $_SERVER['REMOTE_ADDR']);
// Convert json to array
$response = ($response) ? json_decode($response, true) : [];
// If array not empty then perform your logic
if ($res) {
   if (!$captcha || $response['success'] == false) {
    echo "Your CAPTCHA response was wrong";
    exit ; 
  } else { 
   // your code 
     .....
      ....
  }
}

这样可行。

答案 1 :(得分:1)

使用json_decode()

$response = json_decode($response);

并像这样检查

if (!$captcha || $response->success == false) {

要深入了解更多信息:http://php.net/manual/en/function.json-decode.php