如何使用使用php_self action的表单设置recaptcha

如何使用使用php_self action的表单设置recaptcha,php,forms,curl,recaptcha,Php,Forms,Curl,Recaptcha,我的网站看起来像这样 <?php include 'dbd.php'; //DB Login details ?> <!DOCTYPE html> <html> <head> <script src='https://www.google.com/recaptcha/api.js'></script> </head> <body> <?php $sh

我的网站看起来像这样

<?php
  include 'dbd.php';     //DB Login details
?>
<!DOCTYPE html> 
<html> 
<head>
    <script src='https://www.google.com/recaptcha/api.js'></script>
</head> 

<body>

<?php        
$showFormular = true;

if (isset($_POST['submit'])) {
    $error = false;

    if (!$error) {
      $statement = $pdo->prepare("INSERT INTO table (email, name) VALUES (:email, :name,)");
        $result    = $statement->execute(array(
            'email' => $email,
            'name' => $name
        ));

        if ($result) {
            echo "Your Registration was Successful";
            $showFormular = false;
        } else {
            echo 'Could not register your Account';
        }

    }
}

if ($showFormular) {
?>

<form action="<?php echo ($_SERVER['PHP_SELF']); ?>" method="post">

    <input placeholder="Your Forum Name Here" name="name" required>
    <input placeholder="Your Forum Email Here" name="email" required>
    <div class="g-recaptcha" data-sitekey="public key"></div>

    <input name="submit" type="submit">
</form>

<?php
}
?>

</body>
</html>

我希望我解释得足够好,有人能帮助我

为什么要尝试使用curl命令?您可以通过直接使用php代码来实现这一点

require_once('your-imported-autoload.php-path'); ex:Assets/reCaptcha/autoload.php

  $privatekey = "-your private key-";

  $recaptcha = new \ReCaptcha\ReCaptcha($privatekey);

  $resp = $recaptcha->verify($_POST['g-recaptcha-response'],  

  $_SERVER['REMOTE_ADDR']);

  if (!$resp->isSuccess()) {

    // 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

  }
首先,下载此php reCaptcha库并导入您的项目:

其次,在执行操作之后,调用php并在php代码上实现它

require_once('your-imported-autoload.php-path'); ex:Assets/reCaptcha/autoload.php

  $privatekey = "-your private key-";

  $recaptcha = new \ReCaptcha\ReCaptcha($privatekey);

  $resp = $recaptcha->verify($_POST['g-recaptcha-response'],  

  $_SERVER['REMOTE_ADDR']);

  if (!$resp->isSuccess()) {

    // 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

  }
最后,对于cURL,您尝试通过SSL进行连接,并且必须处理它

curl_setopt($verify, CURLOPT_SSL_VERIFYPEER, false);

为什么要尝试使用curl命令?您可以通过直接使用php代码来实现这一点

require_once('your-imported-autoload.php-path'); ex:Assets/reCaptcha/autoload.php

  $privatekey = "-your private key-";

  $recaptcha = new \ReCaptcha\ReCaptcha($privatekey);

  $resp = $recaptcha->verify($_POST['g-recaptcha-response'],  

  $_SERVER['REMOTE_ADDR']);

  if (!$resp->isSuccess()) {

    // 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

  }
首先,下载此php reCaptcha库并导入您的项目:

其次,在执行操作之后,调用php并在php代码上实现它

require_once('your-imported-autoload.php-path'); ex:Assets/reCaptcha/autoload.php

  $privatekey = "-your private key-";

  $recaptcha = new \ReCaptcha\ReCaptcha($privatekey);

  $resp = $recaptcha->verify($_POST['g-recaptcha-response'],  

  $_SERVER['REMOTE_ADDR']);

  if (!$resp->isSuccess()) {

    // 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

  }
最后,对于cURL,您尝试通过SSL进行连接,并且必须处理它

curl_setopt($verify, CURLOPT_SSL_VERIFYPEER, false);

你把你试过的代码放在哪里了-在if里面已经检查表单提交按钮是否在POST数据中了…?你把你试过的代码放在哪里了-在if里面已经检查表单提交按钮是否在POST数据中了…?