我正在使用著名的jQuery Validation 插件,我想实现验证码控件。在他们的演示部分的页面上有,但它似乎有一个问题:当您单击图像刷新时,它不会刷新!这是一个著名的插件,所以我没有发布代码,因为有很多 php 文件,也许你们中的许多人已经知道解决方案。如果需要,我会尝试发布它们。谢谢
编辑
// 指数
<?php
// Make the page validate
ini_set('session.use_trans_sid', '0');
// Include the random string file
require 'js/captcha/rand.php';
// Begin the session
session_start();
// Set the session contents
$_SESSION['captcha_id'] = $str;
?>
<form id="form">
<div id="captchaimage">
<a href="" id="refreshimg" title="Click to refresh image">
<img src="js/captcha/images/image.php?<?php echo time(); ?>" width="132" height="46" alt="Captcha image" />
</a>
</div>
<label for="captcha">insert captcha:</label>
<input type="text" maxlength="6" name="captcha" id="captcha" />
// newsession.php
<?php
// Include the random string file
require 'js/captcha/rand.php';
// Begin a new session
session_start();
// Set the session contents
$_SESSION['captcha_id'] = $str;
?>
// 进程.php
<?php
// Begin the session
session_start();
// To avoid case conflicts, make the input uppercase and check against the session value
// If it's correct, echo '1' as a string
if(strtoupper($_GET['captcha']) == $_SESSION['captcha_id'])
echo 'true';
// Else echo '0' as a string
else
echo 'false';
?>
// rand.php
<?php
// Create a random string, leaving out 'o' to avoid confusion with '0'
$char = strtoupper(substr(str_shuffle('abcdefghjkmnpqrstuvwxyz'), 0, 4));
// Concatenate the random string onto the random numbers
// The font 'Anorexia' doesn't have a character for '8', so the numbers will only go up to 7
// '0' is left out to avoid confusion with 'O'
$str = rand(1, 7) . rand(1, 7) . $char;
?>
//验证
$("#form").validate({
rules: {
'captcha':{
required: true,
remote: "js/captcha/process.php"
}
},
messages: {
'captcha': "error"
},
onkeyup: false
});
// 脚本刷新验证码
$(function(){
$("#refreshimg").click(function(){
$.post('js/captcha/newsession.php');
$("#captchaimage").load('js/captcha/image_req.php');
return false;
});
});
// image_req.php
<?php
// Echo the image - timestamp appended to prevent caching
echo '<a href="" onclick="refreshimg(); return false;" title="Click to refresh image">
<img src="js/captcha/images/image.php?' . time() . '" width="132" height="46" alt="Captcha image" />
</a>';
?>