哪位大侠帮帮我,看看这段代码,为什么无法显跳出登入成功页面而且无法转到指定的主页面,但实际上登入成功了,<form id="form" name="form" method="post" action="">
<div id="container" align="center">
<div id="bgdiv">
<div id="txtdiv1">用户名:
<input id="lgname" name="lgname" type="text" class="txt"/>
</div>
<div id="txtdiv2">密码:
<input id="lgpwd" name="lgpwd" type="password" class="txt"/>
</div>
<div id="txtdiv3">
<input name="lgchk" type="lgchk" id="lgchk" style="width:40px;" maxlength="4">
<img src="identifying.php" width="57" height="22" id='chk_id'/>
<div id="btndiv">
<input type="submit" name="lgbtn" value="登录" id="lgbtn" >
<input type="button" name="fdbtn" value="重置" id="fdbtn" onClick="form.reset();return false;">
<input id="chknm" name="chknm" type="hidden" value="" />
</div>
<div id="regimg" style=" visibility: hidden;"> </div>
</div>
</div>
</form>// JavaScript Document
function $(id){
return document.getElementById(id);
}
window.onload = function(){ $('lgbtn').onclick = check_login;
function check_login(){
if($('lgname').value.match(/^[a-zA-Z_]\w*$/) == null){alert('请正确输入用户名');return false;}
if($('lgpwd').value==''){alert('请输入密码');return false;}
if($('lgchk').value==''){alert('请输入验证码');return false;}
var xmlHttp;
if(window.ActiveXObject) {
xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
} else if(window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
}
var name=document.form.lgname.value;
xmlHttp.open("GET","chk_login.php?name="+name,true);
xmlHttp.onreadystatechange = function(){ alert('dfg'); if(xmlHttp.readyState == 4 ){
if(xmlHttp.status == 200) {
result = xmlHttp.responseText;
if (result=='1'){alert('登入成功');location = 'huixinhouse.php';}
else if(result=='0'){alert('用户名或密码输入错误');locatioin = 'login.php';}
else if(result=='-1'){alert('验证码输入错误');location = 'login.php';}
}
}
}
}
}<?php
session_start();
error_reporting(0);
include("conn.php");
$name = $_POST['lgname'];
$pwd = md5($_POST['lgpwd']);
$createtime = date("Y-m-d H:i:s");
$identifying=$_SESSION['identifying'];
$identifying_post=$_POST['lgchk'];
if ($identifying==$identifying_post){ $sql = mysql_query("select * from tb_user where username = '$name' and password = '$pwd'");
$ob1 = mysql_fetch_object($sql); if ($name == $ob1->username && $pwd == $ob1->password){
$reback='1';
$_SESSION["name"]=$name;
}else{
$reback='0';
}
}else{$reback= '-1';}echo $reback;
?>
<div id="container" align="center">
<div id="bgdiv">
<div id="txtdiv1">用户名:
<input id="lgname" name="lgname" type="text" class="txt"/>
</div>
<div id="txtdiv2">密码:
<input id="lgpwd" name="lgpwd" type="password" class="txt"/>
</div>
<div id="txtdiv3">
<input name="lgchk" type="lgchk" id="lgchk" style="width:40px;" maxlength="4">
<img src="identifying.php" width="57" height="22" id='chk_id'/>
<div id="btndiv">
<input type="submit" name="lgbtn" value="登录" id="lgbtn" >
<input type="button" name="fdbtn" value="重置" id="fdbtn" onClick="form.reset();return false;">
<input id="chknm" name="chknm" type="hidden" value="" />
</div>
<div id="regimg" style=" visibility: hidden;"> </div>
</div>
</div>
</form>// JavaScript Document
function $(id){
return document.getElementById(id);
}
window.onload = function(){ $('lgbtn').onclick = check_login;
function check_login(){
if($('lgname').value.match(/^[a-zA-Z_]\w*$/) == null){alert('请正确输入用户名');return false;}
if($('lgpwd').value==''){alert('请输入密码');return false;}
if($('lgchk').value==''){alert('请输入验证码');return false;}
var xmlHttp;
if(window.ActiveXObject) {
xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
} else if(window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
}
var name=document.form.lgname.value;
xmlHttp.open("GET","chk_login.php?name="+name,true);
xmlHttp.onreadystatechange = function(){ alert('dfg'); if(xmlHttp.readyState == 4 ){
if(xmlHttp.status == 200) {
result = xmlHttp.responseText;
if (result=='1'){alert('登入成功');location = 'huixinhouse.php';}
else if(result=='0'){alert('用户名或密码输入错误');locatioin = 'login.php';}
else if(result=='-1'){alert('验证码输入错误');location = 'login.php';}
}
}
}
}
}<?php
session_start();
error_reporting(0);
include("conn.php");
$name = $_POST['lgname'];
$pwd = md5($_POST['lgpwd']);
$createtime = date("Y-m-d H:i:s");
$identifying=$_SESSION['identifying'];
$identifying_post=$_POST['lgchk'];
if ($identifying==$identifying_post){ $sql = mysql_query("select * from tb_user where username = '$name' and password = '$pwd'");
$ob1 = mysql_fetch_object($sql); if ($name == $ob1->username && $pwd == $ob1->password){
$reback='1';
$_SESSION["name"]=$name;
}else{
$reback='0';
}
}else{$reback= '-1';}echo $reback;
?>
解决方案 »
- 防新浪微博评论功能实现
- 救急啊!!!php168模板出问题了
- 帮我看看这个正规表达式有什么样的作用?
- md5(登陆时输入的密码)与md5(数据库中的密码—注册时经加密录入的密码)不一致?什么原因?
- PHP 配置xdebug就是不行?
- PHP4中有没有函数是做日期的计算的?或者是格式化为日期形式
- 汉字没有被截取,为何却显示乱码?
- **求救** Apache + PHP安装好后,通过Web访问本地服务器的页面时竟然在IE里显示源码??
- php或html编程中如何调用outlook express程序,将整个outlook主界面打开,急急急
- web预约功能问题
- 关于获取QQ邮箱验证码的问题???
- 请教如何分析程序运行日志
JS代码修改为如下即可:
// JavaScript Document
function $(id){
return document.getElementById(id);
}
window.onload = function(){ $('lgbtn').onclick = check_login;
function check_login(){
if($('lgname').value.match(/^[a-zA-Z_]\w*$/) == null){alert('请正确输入用户名');return false;}
if($('lgpwd').value==''){alert('请输入密码');return false;}
if($('lgchk').value==''){alert('请输入验证码');return false;}
var xmlHttp;
if(window.ActiveXObject) {
xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
} else if(window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
}
var name=document.form.lgname.value;
xmlHttp.open("GET","chk_login.php?name="+name,true);
xmlHttp.onreadystatechange = function(){ alert('dfg'); if(xmlHttp.readyState == 4 ){
if(xmlHttp.status == 200) {
result = xmlHttp.responseText;
if (result=='1'){alert('登入成功');location.href = 'huixinhouse.php';}
else if(result=='0'){alert('用户名或密码输入错误');locatioin.href = 'login.php';}
else if(result=='-1'){alert('验证码输入错误');location.href = 'login.php';}
}
}
}
}
}
汗,编辑器有问题,重新发一下:
// JavaScript Document
function $(id){
return document.getElementById(id);
}
window.onload = function(){ $('lgbtn').onclick = check_login;
function check_login(){
if($('lgname').value.match(/^[a-zA-Z_]\w*$/) == null){alert('请正确输入用户名');return false;}
if($('lgpwd').value==''){alert('请输入密码');return false;}
if($('lgchk').value==''){alert('请输入验证码');return false;}
var xmlHttp;
if(window.ActiveXObject) {
xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
} else if(window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
}
var name=document.form.lgname.value;
xmlHttp.open("GET","chk_login.php?name="+name,true);
xmlHttp.onreadystatechange = function(){ alert('dfg'); if(xmlHttp.readyState == 4 ){
if(xmlHttp.status == 200) {
result = xmlHttp.responseText;
if (result=='1'){alert('登入成功');location.href = 'huixinhouse.php';}
else if(result=='0'){alert('用户名或密码输入错误');locatioin.href = 'login.php';}
else if(result=='-1'){alert('验证码输入错误');location.href = 'login.php';}
}
}
}
}
}
PS: 不能正确跳转的原因在于location.href='要跳转的URL',而楼主的代码中少了.href,因此不能正确跳转