Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/241.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
带有recaptcha的PHP表单_Php_Forms_Recaptcha - Fatal编程技术网

带有recaptcha的PHP表单

带有recaptcha的PHP表单,php,forms,recaptcha,Php,Forms,Recaptcha,我正在使用带有重新验证码的php联系人表单,但不知道应该使用什么值: $client_captcha_response = $_POST['g-recaptcha-response']; 当我试图通过另一个验证代码页面收集此信息时,g-recompcha-response中会出现问题,但每次提交时,我得到的g-recompcha-response 提交id上的我的表单显示一个空白页 HTML端代码: <form method="post" action="contactform.

我正在使用带有重新验证码的php联系人表单,但不知道应该使用什么值:

$client_captcha_response = $_POST['g-recaptcha-response'];
当我试图通过另一个验证代码页面收集此信息时,
g-recompcha-response
中会出现问题,但每次提交时,我得到的
g-recompcha-response

提交id上的我的表单显示一个空白页

HTML端代码:

    <form method="post" action="contactform.php">
  <label>Your Name (required):</label>
    <input name="name" type="text" placeholder="Enter your name here">
  <label>Email Address (required):</label>
    <input name="email" type="email" placeholder="Enter your email address here">
  <label>Your Message (required):</label>
    <textarea name="message" placeholder="Write your message here"></textarea>
  <div class="g-recaptcha" data-sitekey="6LfTVfgSAAAAADvdpWzYkifBXTmJ8ohokl_lIKgH"></div>
  <input id="submit" name="submit" type="submit" value="Submit Form">
</form>
<?php
$your_secret = "<Secret key>";
$client_captcha_response = $_POST['g-recaptcha-response'];
$user_ip = $_SERVER['REMOTE_ADDR'];

$captcha_verify = open_https_url("https://www.google.com/recaptcha/api/siteverify?secret=$your_secret&response=$client_captcha_response&remoteip=$user_ip");
$captcha_verify_decoded = json_decode($captcha_verify);
if(!$captcha_verify_decoded->success)
  die('DIRTY ROBOT');

$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$human = $_POST['human'];
$from = 'From: My Website';
$to = 'myemail@gmail.com';
$subject = 'Request Form';

$body = "Name: $name \n E-Mail: $email \nMessage:\n$message";

if ($_POST['submit']) {
    if ($email != '') {
        if ($human == '4') {                 
            if (mail ($to, $subject, $body, $from)) { 
                echo '<p>You have successfully submitted your information to PS4RS. Subscribers to our mailing list will begin to periodically receive updates.</p>';
            } else { 
                echo '<p>Something went wrong, go back and try again!</p><p><input type="button" value="Go Back" onclick="history.back(-1)" class="goback" /></p>'; 
            } 
        } else if ($_POST['submit'] && $human != '4') {
            echo '<p>You answered the anti-spam question incorrectly!</p><p><input type="button" value="Go Back" onclick="history.back(-1)" class="goback" /></p>';
        }
    } else {
        echo '<p>You need to fill in all required fields!!</p><p><input type="button" value="Go Back" onclick="history.back(-1)" class="goback" /></p>';
    }
}
?>

您的姓名(必填):
电子邮件地址(必填):
您的信息(必填):
PHP端代码:

    <form method="post" action="contactform.php">
  <label>Your Name (required):</label>
    <input name="name" type="text" placeholder="Enter your name here">
  <label>Email Address (required):</label>
    <input name="email" type="email" placeholder="Enter your email address here">
  <label>Your Message (required):</label>
    <textarea name="message" placeholder="Write your message here"></textarea>
  <div class="g-recaptcha" data-sitekey="6LfTVfgSAAAAADvdpWzYkifBXTmJ8ohokl_lIKgH"></div>
  <input id="submit" name="submit" type="submit" value="Submit Form">
</form>
<?php
$your_secret = "<Secret key>";
$client_captcha_response = $_POST['g-recaptcha-response'];
$user_ip = $_SERVER['REMOTE_ADDR'];

$captcha_verify = open_https_url("https://www.google.com/recaptcha/api/siteverify?secret=$your_secret&response=$client_captcha_response&remoteip=$user_ip");
$captcha_verify_decoded = json_decode($captcha_verify);
if(!$captcha_verify_decoded->success)
  die('DIRTY ROBOT');

$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$human = $_POST['human'];
$from = 'From: My Website';
$to = 'myemail@gmail.com';
$subject = 'Request Form';

$body = "Name: $name \n E-Mail: $email \nMessage:\n$message";

if ($_POST['submit']) {
    if ($email != '') {
        if ($human == '4') {                 
            if (mail ($to, $subject, $body, $from)) { 
                echo '<p>You have successfully submitted your information to PS4RS. Subscribers to our mailing list will begin to periodically receive updates.</p>';
            } else { 
                echo '<p>Something went wrong, go back and try again!</p><p><input type="button" value="Go Back" onclick="history.back(-1)" class="goback" /></p>'; 
            } 
        } else if ($_POST['submit'] && $human != '4') {
            echo '<p>You answered the anti-spam question incorrectly!</p><p><input type="button" value="Go Back" onclick="history.back(-1)" class="goback" /></p>';
        }
    } else {
        echo '<p>You need to fill in all required fields!!</p><p><input type="button" value="Go Back" onclick="history.back(-1)" class="goback" /></p>';
    }
}
?>

以下是我的代码,运行时没有问题:

客户端:

<div class="g-recaptcha" data-sitekey="PUBLIC_KEY"></div>
if (isset($_POST['g-recaptcha-response'])) {
    $captcha = $_POST['g-recaptcha-response'];
    $privatekey = "SECRET_KEY";
    $url = 'https://www.google.com/recaptcha/api/siteverify';
    $data = array(
        'secret' => $privatekey,
        'response' => $captcha,
        'remoteip' => $_SERVER['REMOTE_ADDR']
    );

    $curlConfig = array(
        CURLOPT_URL => $url,
        CURLOPT_POST => true,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_POSTFIELDS => $data
    );

    $ch = curl_init();
    curl_setopt_array($ch, $curlConfig);
    $response = curl_exec($ch);
    curl_close($ch);
}

$jsonResponse = json_decode($response);

if ($jsonResponse->success == "true")
    doSomething();
else
    doSomeOtherThing();

工作!:)

如何将
g-recaptcha-response
发布到服务器?我在你的表单中没有看到输入这个名字。事实上我对此感到困惑。你需要在表单中输入一个有这个名字的输入字段,以便用户键入验证码,对吗?类似于:
是的,我同意让我试试这个。武士,这个怎么样:因为我的表格已经显示了RECAPATCH而没有“”问题,提交后我得到一个空白页:(