【发布时间】:2017-08-25 18:13:27
【问题描述】:
使用下面的代码,我想要一个页面,当它第一次加载时,它会要求重新验证,然后(当会话有效时)它不再需要它。 当我在使用 recaptcha 验证后单击 Open Admin Tools 时,它会显示它应该做什么;它显示 recaptcha 已完成,选项: 但是当我点击测试时,它只会回到要求我完成recaptcha。我该如何做到这一点,以便每个(有效)会话只执行一次?
<html>
<head>
<title>Admin Settings Page</title>
<script src='https://www.google.com/recaptcha/api.js'></script>
</head>
<body>
<?php
if (!isset($_POST['g-recaptcha-response'])){
?>
<p>Please successfully complete the reCaptcha below to access the page.</p>
<form action="" method="post">
<div class="g-recaptcha" data-sitekey="sitekey"></div>
<input type="submit" value="Open Admin Tools" />
</form>
<?php
} else {
$captcha;
if (isset($_POST['g-recaptcha-response'])){
$captcha=$_POST['g-recaptcha-response'];
}
if (!isset($captcha))
$captcha = false;
if (!$captcha){
echo '<h2>Please check the the captcha form.</h2>';
exit;
}
$secretKey = "secretkey";
$ip = $_SERVER['REMOTE_ADDR'];
$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 '<h2>reCAPTCHA expired</h2>';
} else {
?>
<p>Recaptcha Completed, Options:</p>
<form action="" method="post">
<input type="submit" value="test" />
</form>
<?php
}
}
?>
<br />
</body>
</html>
我有一个临时解决方法,我正在通过 javascript 使用动态更改内容,但我仍然想知道是否可以按照我上面的要求进行操作。
【问题讨论】: