【问题标题】:recaptcha integration with separate pagesrecaptcha 与单独页面的集成
【发布时间】:2015-10-12 08:45:28
【问题描述】:

我正在尝试将验证码添加到我的网站,并试图让谢谢你在不同的页面中打开,而不是在同一个文件中使用 php,我该怎么做?

我知道这是表单周围的 php 部分,但我不知道如何更改它以发送到单独的感谢页面。

编辑 - 如果我添加一个操作页面,验证码会中断,但表单会提交,当我采取行动时,验证码有效但不提交

<!DOCTYPE html>
<?php

// grab recaptcha library
require_once "recaptchalib.php";

  // your secret key
$secret = "MY SECRET KEY";

// empty response
$response = null;

// check secret key
$reCaptcha = new ReCaptcha($secret);

// if submitted check response
if ($_POST["g-recaptcha-response"]) {
    $response = $reCaptcha->verifyResponse(
        $_SERVER["REMOTE_ADDR"],
        $_POST["g-recaptcha-response"]
    );
}
?>
<html lang="en">
  <head>
<!--js-->
<script src='https://www.google.com/recaptcha/api.js'></script>
<title>MATA captcha test</title>

</head>

<body>


<?php
  if ($response != null && $response->success) {
    echo "Hi " . $_POST["name"] . " (" . $_POST["email"] . "), thanks for submitting the form!";
  } else {
?>
    <form action="" method="post">

      <label for="name">Name:</label>
      <input name="name" required><br />

      <label for="email">Email:</label>
      <input name="email" type="email" required><br />

      <div class="g-recaptcha" data-sitekey="MY KEY"></div>

      <input type="submit" value="Submit" />

    </form>

<?php } ?>


  </body>
</html>

【问题讨论】:

    标签: php google-api captcha recaptcha


    【解决方案1】:

    这是你的意思吗?

    &lt;form action="insert_your_site_here.php" method="post"&gt;

    而不是

    &lt;form action="" method="post"&gt;

    【讨论】:

    • 当我添加验证码不再起作用的动作时,验证码似乎只有在它不发布到另一个页面时才起作用?
    • 您能否进一步解释您所说的不工作是什么意思?其他页面是否存在?你在另一页上使用POST 吗?验证码是否验证失败?
    • 当添加操作页面时,页面只是向前移动而无需使用验证码进行验证,但是当操作页面被删除时,需要验证码来发送表单,但是表单实际上并没有提交..这更有意义吗?
    • 在另一页上,您是否在提交表单之前对POST$response 进行了所有检查?
    • 我认为这与 success) { echo "Hi" 。 $_POST["name"] 。 " (" . $_POST["email"] . "),感谢您提交表单!"; } else { ?> 这个位码
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-11
    • 2017-10-30
    • 2017-07-10
    • 2015-08-12
    相关资源
    最近更新 更多