我一直试图让这个验证码工作了一段时间,但我不能让它工作,无论我试图做什么。
当我改变!==到只是!=有人建议,当我按下表单的“提交”按钮时,表单提交将以“真”响应进行,即使按下reCAPTCHA框或忽略按下它。var_dump($responseKeys)的输出总是给我一个“空”值,所以我不能找出什么是错的。
有人知道为什么它不工作吗?
菲律宾
if (isset($_POST)) {
$captcha = $_POST['g-recaptcha-response'];
$ip = $_SERVER['REMOTE_ADDR'];
$secretkey = 'SECRET KEY';
$response = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret=' . $secretkey . '&response=' . $captcha . '&remoteip=' . $ip);
$responseKeys = json_decode($response, true);
if (intval($responseKeys['success']) != 1) {
//echo 'TRUE';
//echo "<br>";
//echo var_dump($responseKeys)."<br>";
//exit;
} else {
//echo 'FALSE';
//echo "<br>";
//echo var_dump($responseKeys)."<br>";
// exit;
}
}
超文本标记语言
<div class="span9 page_sidebar registerForm">
<?php
if (isErrors())
{
echo outputErrors();
}
?>
<div class="well">
<p>
<?php echo t('register_intro_text', 'Please enter your information below to register for an account. Your new account password will be sent to your email address.'); ?>
</p>
<form id="regerform" method="post" action="https://<?php echo _CONFIG_SITE_FULL_URL; ?>/register.<?php echo SITE_CONFIG_PAGE_EXTENSION; ?>" class="form">
<div class="third">
<label for="title">
<?php echo t("title", "title"); ?>:
</label>
<select autofocus="autofocus" tabindex="1" id="title" name="title">
<option value="Mr"><?php echo t('title_mr', 'Mr'); ?></option>
<option value="Mrs"><?php echo t('title_mrs', 'Mrs'); ?></option>
<option value="Miss"><?php echo t('title_miss', 'Miss'); ?></option>
<option value="Dr"><?php echo t('title_dr', 'Dr'); ?></option>
<option value="Pro"><?php echo t('title_pro', 'Pro'); ?></option>
</select>
</div>
<div class="third">
<label for="firstname">
<?php echo t("firstname", "firstname"); ?>:
</label>
<input type="text" tabindex="1" value="<?php echo isset($firstname) ? safeOutputToScreen($firstname) : ''; ?>" id="firstname" name="firstname">
</div>
<div class="thirdLast">
<label for="lastname">
<?php echo t("lastname", "lastname"); ?>:
</label>
<input type="text" tabindex="1" value="<?php echo isset($lastname) ? safeOutputToScreen($lastname) : ''; ?>" id="lastname" name="lastname">
</div>
<div class="clear"></div>
<div>
<label for="emailAddress">
<?php echo t("email_address", "email address"); ?>:
</label>
<input type="text" tabindex="1" value="<?php echo isset($emailAddress) ? safeOutputToScreen($emailAddress) : ''; ?>" id="emailAddress" name="emailAddress">
</div>
<div>
<label for="emailAddressConfirm">
<?php echo t("email_address_confirm", "Email Confirm"); ?>:
</label>
<input type="text" tabindex="2" value="<?php echo isset($emailAddressConfirm) ? safeOutputToScreen($emailAddressConfirm) : ''; ?>" id="emailAddressConfirm" name="emailAddressConfirm">
</div>
<div class="thirdLast">
<label for="username">
<?php echo t("username", "username"); ?>:
</label>
<input type="text" tabindex="3" value="<?php echo isset($username) ? safeOutputToScreen($username) : ''; ?>" id="username" name="username">
</div>
<div class="clear"></div>
<?php if(SITE_CONFIG_REGISTER_FORM_SHOW_CAPTCHA == 'yes'): ?>
<div class="g-recaptcha" data-sitekey="PRIVATE KEY"></div>
<?php endif; ?>
<div class="buttonWrapper">
<button type="submit" name="submit" class="btn btn-primary" tabindex="99"><?php echo t("register", "register"); ?></button>
</div>
<input type="hidden" value="1" name="submitme"/>
</form>
<div class="disclaimer">
<?php echo t('by_clicking_register_you_agree_to_our_terms', 'By clicking \'register\', you agree to our <a href="terms.[[[SITE_CONFIG_PAGE_EXTENSION]]]" target="_blank">terms</a>.', array('SITE_CONFIG_PAGE_EXTENSION'=>SITE_CONFIG_PAGE_EXTENSION)); ?>
</div>
<div class="clear"></div>
</div>
</div>
1条答案
按热度按时间xxhby3vn1#
验证用户的方法稍有不同。
g-recaptcha-response
通过POST请求发送到服务器端脚本,并与注册时获得的reCAPTCHA密钥沿着,你把它沿着Google来判断用户是否是机器人。响应是JSON响应,因此我们将使用file_get_contents()
和json_decode()
来获取响应,并决定如何使用脚本。这个例子将给予你一个想法来编写自己的代码。