Php 带有jQuery验证插件的验证码
我正在使用著名的,我想实现验证码控制。在他们的演示部分有一个问题:当你点击图片刷新时,它不会刷新!这是一个著名的插件,所以我没有发布代码,因为有很多php文件,也许你们中的许多人已经知道解决方案。如果需要的话,我会尽量把它们贴出来。谢谢 编辑 //索引Php 带有jQuery验证插件的验证码,php,jquery,jquery-validate,captcha,Php,Jquery,Jquery Validate,Captcha,我正在使用著名的,我想实现验证码控制。在他们的演示部分有一个问题:当你点击图片刷新时,它不会刷新!这是一个著名的插件,所以我没有发布代码,因为有很多php文件,也许你们中的许多人已经知道解决方案。如果需要的话,我会尽量把它们贴出来。谢谢 编辑 //索引 <?php // Make the page validate ini_set('session.use_trans_sid', '0'); // Include the random string file require 'js/c
<?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" />
//脚本刷新验证码
$(function(){
$("#refreshimg").click(function(){
$.post('js/captcha/newsession.php');
$("#captchaimage").load('js/captcha/image_req.php');
return false;
});
});
//image_req.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
// 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';
?>
<?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;
?>
<?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>';
?>
.good{颜色:绿色;}
.bad{颜色:红色;}
#验证码{
-moz用户选择:无;
-khtml用户选择:无;
-webkit用户选择:无;
用户选择:无;
}
$(function(){//在文档准备就绪时运行,加载元素
$(“#刷新”)。单击(函数(){
$(“#验证码”).load(location.href+“#验证码”);
});
});
$(函数(){
$(“#发送”)。单击(函数(evt){
if($('#check').val()==$('#verify').val()){
$(“#结果”).html(“正确”);
evt.preventDefault();
}否则{
$(“#结果”).html(“不正确”);
evt.preventDefault();
}
});
});
验证码集于一身
你的问题是什么?演示中的示例不起作用,或者在您自己的站点上对您不起作用?您可以将链接放到此图像上。它会的refresh@ben:它在我自己的网站上不起作用,就像它在演示中不起作用一样@croios:使用您的解决方案,它会刷新,但会重新生成相同的图像!如果我再次单击刷新它,请重新加载整个页面!我在发布的代码中看不到任何id为#refreshimg的元素,也看不到第三方工具中的#captchaimageAs的元素,最好提供一个代码示例。还要注意的是,这些答案意味着可以存活数年,并且仍然有用。我担心免费文件共享网站很可能会随着时间的推移而腐烂。
<?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>';
?>
<html>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<style>
.good {color: green;}
.bad {color: red;}
#captcha {
-moz-user-select: none;
-khtml-user-select: none;
-webkit-user-select: none;
user-select: none;
}
</style>
<?php
function background($length = 6) {
$characters = "ABCDEF0123456789";
$string = "#";
for ($p = 0; $p < $length; $p++) {
$string .= $characters[mt_rand(0, strlen($characters) - 1)];}
return $string;
}
$f = background();
function signs($length = 6) {
$characters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnoprstuvwxyz";
$string = "";
for ($p = 0; $p < $length; $p++) {
$string .= $characters[mt_rand(0, strlen($characters) - 1)];}
return $string;
}
$a = signs();
?>
<script>
$(function() { //run when the document's ready, elements are loaded
$("#refresh").click(function() {
$("#captcha").load(location.href + " #captcha");
});
});
</script>
<script>
$(function() {
$("#send").click(function(evt) {
if ($('#check').val() === $('#verify').val()) {
$("#result").html("<h3 class='good'>Correct</h3>");
evt.preventDefault();
} else {
$("#result").html("<h3 class='bad'>Incorrect</h3>");
evt.preventDefault();
}
});
});
</script>
<head>
<h1>Captcha all in one</h1>
<hr />
</head>
<body>
<div id="captcha" style="height: 50px; width: 125px; background-color: <?php echo $f; ?>"><font face="OCRB" style="font-size: xx-large;" color="<?php echo $a; ?>">
<p id="secimage"><?php echo $a; ?></p></font><input type="text" id="check" value="<?php echo $a; ?>" style="display: none;"/></div>
<button id="refresh">↑↓</button>
<input id="verify" type="text" placeholder="Enter code" />
<button id="send">Check</button>
<div id="result"></div>
</body>
</html>