这个登录程序的验证码如何用JS去判断?请各位高手相助
时间:2010-07-12
来源:互联网
session_start();
include("conn.php");
if($_POST['btnLogin']){
$user=$_POST['user'];
$pwd=$_POST['pass'];
$yzm=$_POST['yzm'];
$sql="select * from `access` where `name`='$user' and `pwd`='$pwd'";
$rs=mysql_query($sql);
$result=mysql_fetch_array($rs);
if($result){
header("location:list.php");
$_SESSION[user]=$user;
}else{
echo "用户名或密码错误!";
}
}
?>
<html>
<head>
<title>添加留言</title>
</head>
<script language="javascript">
function check(){
if(document.login.user.value==""){
alert("用户名不能为空!");
login.user.focus();
return false;
}
if(document.login.pass.value==""){
alert("密码不能为空!");
login.pass.focus();
return false;
}
if(document.login.yzm.value==""){
alert("验证码不能为空!");
login.yzm.focus();
return false;
}
if(document.login.yzm.value!=document.login.hide.value){
alert("验证码错误!");
login.yzm.focus();
return false;
}
}
</script>
<body>
<?php
include("top.html");
?>
<center>
<table border="1">
<form name="login" method="post" action="login.php" onsubmit="return check()">
<tr>
<td>昵称:</td>
<td><input type="text" name="user"></td>
</tr>
<tr>
<td>密码:</td>
<td><input type="password" name="pass"></td>
</tr>
<tr>
<td>验证码:</td>
<td><input type="text" size="4" name="yzm"><img src="imagecode.php"></td>
<input type="hidden" name="hide" value="<?php echo $_SESSION['check_pic']?>">
</tr>
<tr align="center">
<td colspan="2"><input type="submit" name="btnLogin" value="登录">
<input type="reset" name="btnCancel" value="取消"> <a href="reg.php">注册</a>
</td>
</tr>
</form>
</table>
</center>
</body>
</html>
说明:其中$_SESSION['check_pic']为imagecode.php 产生的验证码
这个登录程序的验证码如何用JS去判断?请各位高手相助
作者: phua 发布时间: 2010-07-12
if(this.value.toUpperCase()!=document.forms[0].hide.value.toUpperCase()){
alert('输入不正确')
return false;
}
}
作者: ynwcel 发布时间: 2010-07-12
作者: phua 发布时间: 2010-07-12
if(document.login.yzm.value!=document.login.hide.value){
alert("输入不正确");
login.yzm.focus();
return false;
}
//form中的判断验证码代码
<tr>
<td>验证码:</td>
<td><input type="text" size="4" name="yzm"><img src="imagecode.php"></td>
<input type="hidden" name="hide" value="<?php echo $_SESSION['check_pic']?>">
<?php echo $_SESSION['check_pic']?>
</tr>
请大侠帮我看一下,到底哪错了?
作者: phua 发布时间: 2010-07-12
作者: ysz9999 发布时间: 2010-07-12
作者: 李思 发布时间: 2010-07-12
然后提交的时候判断
function check(){
if(doucument.form.login.yzm.value != document.form.login.hide.value)
{
alert('验证码不正确');
return false;
}
}
">
<form name="login" method="post" action="login.php" onsubmit="return check()">
作者: yuejide 发布时间: 2010-07-12
这个语句,把imagecode.php中的值传到hide这个框中,然后在通过yzm中的值与hide框中的值进行判断,
我觉得我的思路没错的,我是传值了
作者: phua 发布时间: 2010-07-12
作者: 改良继 发布时间: 2010-07-12
这一句的"hidden"改为“text”,就会看到他的值与验证码的值是不相等的
作者: jetshow 发布时间: 2010-09-06
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28