我正在创建一个带有验证码的表单,并且我将这些代码存储在隐藏的输入框中,但输入框存储以前的会话代码。我正在猜测它与session_stars有什么共同之处,我一直在摆弄它,但无济于事。会话回显的前一个变量
请问有人能指点我正确的方向!
php文件:
<body>
<?php
session_start();
?>
...
<div id="reg-field">
<h1>Human Verification</h1>
<div id="captions">
<img src="PHP/captcha.php" style="float: right;" class="cnr-all" />
</div>
<form name="Form3" method="post">
<input type="text" id="captcha-bar" class="cnr-all" name="answer" placeholder="Enter Code Here" />
<input type="hidden" name="answer2" value="<?php echo $_SESSION['captcha']; ?>"/>
<input type="button" id="captcha-reload" class="cnr-all" onclick="window.location.href = window.location.href">
<span id="captchaConfirm" class="confirmMessage" style="margin: 12.5px 0px"></span>
</form>
</div>
...
</body>
验证码PHP创建者:
<?php
session_start();
header("Expires: Tue, 01 Jan 2013 00:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$randomString = '';
for ($i = 0; $i < 5; $i++)
{
$randomString .= $chars[rand(0, strlen($chars)-1)];
}
$_SESSION['captcha'] = strtolower($randomString);
$im = @imagecreatefrompng("captcha_bg.png");
imagettftext($im, 30, 0, 10, 38, imagecolorallocate ($im, 0, 0, 0), 'larabiefont.ttf', $randomString);
header ('Content-type: image/png');
imagepng($im, NULL, 0);
imagedestroy($im);
?>
我使用Javascript验证和比较两个字段,它仍然有可能这样吗? – horHAY
更好地通过与服务器的AJAX呼叫比较验证码。将用户输入发送到服务器,PHP会对其进行比较,向客户端发送响应,并根据PHP的结果最终向用户提供反馈。 –
我必须使用JS(不要问),据我所知这是最安全的选择(我知道安全风险),虽然对于人类验证它应该没问题? – horHAY