Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 我对涉及reCAPTCHA的php感到困惑_Javascript_Php_Recaptcha - Fatal编程技术网

Javascript 我对涉及reCAPTCHA的php感到困惑

Javascript 我对涉及reCAPTCHA的php感到困惑,javascript,php,recaptcha,Javascript,Php,Recaptcha,我正试图建立一个非常基本的网站,包括reCAPTCHA。我已经获得了我的站点密钥和秘密密钥,并且到目前为止,我已经完成了两个教程的学习,但运气不佳 <form method="post" action="verify.php"> Number:<br> <input type="text" name="number"><br> <?php require_once('recaptchalib.php'

我正试图建立一个非常基本的网站,包括reCAPTCHA。我已经获得了我的站点密钥和秘密密钥,并且到目前为止,我已经完成了两个教程的学习,但运气不佳

  <form method="post" action="verify.php">
    Number:<br> 
    <input type="text" name="number"><br>
    <?php
      require_once('recaptchalib.php');
      $publickey = "your_public_key"; // you got this from the signup page
      echo recaptcha_get_html($publickey);
    ?>
    <input type="submit" />
  </form>

  <!-- more of your HTML content -->
</body>
sites的目标是使用表单从用户处获取一个数字作为输入,并在reCAPTCHA成功并按下submit按钮后显示一个字符串

  <form method="post" action="verify.php">
    Number:<br> 
    <input type="text" name="number"><br>
    <?php
      require_once('recaptchalib.php');
      $publickey = "your_public_key"; // you got this from the signup page
      echo recaptcha_get_html($publickey);
    ?>
    <input type="submit" />
  </form>

  <!-- more of your HTML content -->
</body>
这是到目前为止我的代码

<!DOCTYPE HTML>
<html> <!-- template-->
<head>
  <title>template</title>

  <script src="lib/jquery-2.1.4.min.js"></script> 
  <script src='https://www.google.com/recaptcha/api.js'></script>


</head> 

<body>

<form action="/verify.php" method="get">
  Number:<br>
  <input type="text" name="firstname"><br>
  <div class="g-recaptcha" data-sitekey="6LcKeGwUAAAAAOdDqu2CzJxZdgYUXEUEPQKZBOtn"></div>
  <input type="submit" value="Submit" />

</form>

</body>
</html>
  <form method="post" action="verify.php">
    Number:<br> 
    <input type="text" name="number"><br>
    <?php
      require_once('recaptchalib.php');
      $publickey = "your_public_key"; // you got this from the signup page
      echo recaptcha_get_html($publickey);
    ?>
    <input type="submit" />
  </form>

  <!-- more of your HTML content -->
</body>

模板
编号:

这是我的php

<html>
<body>

The number is <?php echo $_GET["number"]; ?><br>

<?php 
  if ($_GET["number"] == 42)
  echo "42 is the right answer!";
?>

</body>
</html>
  <form method="post" action="verify.php">
    Number:<br> 
    <input type="text" name="number"><br>
    <?php
      require_once('recaptchalib.php');
      $publickey = "your_public_key"; // you got this from the signup page
      echo recaptcha_get_html($publickey);
    ?>
    <input type="submit" />
  </form>

  <!-- more of your HTML content -->
</body>

号码是
到目前为止,该网站工作良好。。。除了我不知道如何添加reCAPTCHA代码和Google文档之外,我很困惑,因为我对php知之甚少

  <form method="post" action="verify.php">
    Number:<br> 
    <input type="text" name="number"><br>
    <?php
      require_once('recaptchalib.php');
      $publickey = "your_public_key"; // you got this from the signup page
      echo recaptcha_get_html($publickey);
    ?>
    <input type="submit" />
  </form>

  <!-- more of your HTML content -->
</body>

非常感谢您提供任何代码示例或简单文档的链接。这是我关于stackoverflow的第一篇文章。。。我希望我能很好地遵守规则

这将是您的verify.php

$post_data = http_build_query(
    array(
        'secret' => CAPTCHA_SECRET, //as provided from google
        'response' => $_POST['g-recaptcha-response'],
        'remoteip' => $_SERVER['REMOTE_ADDR']
    )
);
$opts = array('http' =>
    array(
        'method'  => 'POST',
        'header'  => 'Content-type: application/x-www-form-urlencoded',
        'content' => $post_data
    )
);
$context  = stream_context_create($opts);
$response = file_get_contents('https://www.google.com/recaptcha/api/siteverify', false, $context);
$result = json_decode($response);
if ($result->success) {
//success,
echo $_GET["firstname"]; //your input field name was 'firstname' not 'number'

}else{
echo 'we think you are a bot';
//fail

}
  <form method="post" action="verify.php">
    Number:<br> 
    <input type="text" name="number"><br>
    <?php
      require_once('recaptchalib.php');
      $publickey = "your_public_key"; // you got this from the signup page
      echo recaptcha_get_html($publickey);
    ?>
    <input type="submit" />
  </form>

  <!-- more of your HTML content -->
</body>

我建议将您的HTML代码更改为:

  <form method="post" action="verify.php">
    Number:<br> 
    <input type="text" name="number"><br>
    <?php
      require_once('recaptchalib.php');
      $publickey = "your_public_key"; // you got this from the signup page
      echo recaptcha_get_html($publickey);
    ?>
    <input type="submit" />
  </form>

  <!-- more of your HTML content -->
</body>

  <form method="post" action="verify.php">
    Number:<br> 
    <input type="text" name="number"><br>
    <?php
      require_once('recaptchalib.php');
      $publickey = "your_public_key"; // you got this from the signup page
      echo recaptcha_get_html($publickey);
    ?>
    <input type="submit" />
  </form>

  <!-- more of your HTML content -->
</body>

编号:

  <form method="post" action="verify.php">
    Number:<br> 
    <input type="text" name="number"><br>
    <?php
      require_once('recaptchalib.php');
      $publickey = "your_public_key"; // you got this from the signup page
      echo recaptcha_get_html($publickey);
    ?>
    <input type="submit" />
  </form>

  <!-- more of your HTML content -->
</body>
并在verify.php中添加以下内容:

  <form method="post" action="verify.php">
    Number:<br> 
    <input type="text" name="number"><br>
    <?php
      require_once('recaptchalib.php');
      $publickey = "your_public_key"; // you got this from the signup page
      echo recaptcha_get_html($publickey);
    ?>
    <input type="submit" />
  </form>

  <!-- more of your HTML content -->
</body>
<?php
require_once('recaptchalib.php');
$privatekey = "your_private_key";
$resp = recaptcha_check_answer ($privatekey,
                            $_SERVER["REMOTE_ADDR"],
                            $_POST["recaptcha_challenge_field"],
                            $_POST["recaptcha_response_field"]);

if (!$resp->is_valid) {
  // What happens when the CAPTCHA was entered incorrectly
  die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
     "(reCAPTCHA said: " . $resp->error . ")");
} else {
  // Your code here to handle a successful verification
  if (isset($_POST['number']) && $_POST['number'] == '42') {
    echo "42 is the right answer!";
  }
}
?>

OP需要
recaptchalib.php
我使用的教程。。。向我介绍了“recaptchalib.php”文件。。。但是当我运行代码时。。。我收到错误。。。主要的一个似乎连接到第124行,这一行的部分说[错误代码],我想用这个文件来帮助我更好地理解reCAPTCHA和php。。。但是对于像我这样的外行来说,关于这些东西的教程似乎大部分都没有。谢谢你的回复,我修正了你注意到的打字错误,并添加了我的密钥,但是。。。现在,当我运行应用程序时,我得到了以下错误:“注意:未定义的索引:C:\Users\Brandon\Google Drive\WWWWWW\Middle\verify.php中的g-recaptcha-response,在第10行”我的问题可能是我使用的是localhost吗?我有localhost和127.0.0.1作为我的域用于RecaptchayYour表单需要使用POST,不,我很感激我爱你们,哈哈,太谢谢你们了!几年来,我一直想建立一个这样的reCAPTCHA东西