登陆框的主页(有点简陋)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>用户登录</title>
<script type="text/javascript" src="./js/check.js"></script>
</head>
<body>
<form action="check.php" method="post">
<table border="0">
<tr><td>用户名:</td><td><input type="text" id="name" name="name" οnmοuseοut="check()" /></td><td><div id="result"></div></td></tr>
<tr><td>密码:<td><input type="password" id="password" name="password" /></td></tr>
<tr><td colspan="2"><input type="submit" value="登陆" οnclick="submitdata" /></td></tr>
</table>
</form>
</body>
</html>
本来是想用ajax把用户和密码传到页面上判断的的,后来还是不行,用的传统方法判断密码,只能用ajax判断用户名
//创建XMLHttpRequest对象
//声明体局变量
//a获取username
function check(){
xmlhttp = new XMLHttpRequest();
var username = document.getElementById("name").value;
if(window.XMLHttpRequest){
xmlhttp = new XMLHttpRequest(); //使用新的浏览器
//针对firefox的一个bug
if(xmlhttp.overrideMimeType){
xmlhttp.overrideMimeType("text/xml");
}
}else if(window.ActiveXObject){
//IE5.0 5.5 6.0
//旧版浏览器
var activename = ['MSXML2.XMLHTTP','Microsoft.XMLHTTP'];
for(var i=0;i<activename.length;i++){
try{
xmlhttp = new ActiveXObject(activename[i]);
break;
}
catch(e){
//判断出现异常后
}
}
}
//第二步:指定响应的处理函数
xmlhttp.onreadystatechange=callback;
function callback(){
//接收服务器端(demo.php)返回来的xml数据动动态写入div预留空间
//接收信息前提条件是
//第一个条件HTTP 请求 的状态度为"HTP"
if(xmlhttp.readyState == 4){
if(xmlhttp.status == 200){
var responseText = xmlhttp.responseText;
//动态写入DIV的预留空间
//获取div元素节点
var divNode = document.getElementById("result");
//写入文本信息
divNode.innerHTML = responseText;
}
}
}
xmlhttp.open('GET','demo.php?name='+username,true); //传输数据
xmlhttp.send(null);
}
demo文件 用来显示用户名存在是否
<?php
include 'conn.php';
@$_name = $_GET['name']; //获取客户端用户信息
$sql="select name from user";
$rs=mysql_query($sql);
$test=0; //由$test 判断是否存在
while ($row = mysql_fetch_array($rs)){ //将数据库中的数据转为数组
if($_name == $row[0]){
$test=1;
echo "OK";
}
}
if($test==0){
echo $_name."不存在";
}
?>
<?php
include 'conn.php';
$_name = $_POST['name']; //获取客户端用户信息
$_password = $_POST['password'];
$sql="select * from user where name='".$_name."' and password='".$_password."'";
$rs=mysql_query($sql);
if(mysql_num_rows($rs)){
?>
<script type="text/javascript">
<!--
alert("登陆成功,确定后跳转到管理首页!");
location="index.php";
//-->
</script>
<?php
}else{
?>
<script type="text/javascript">
<!--
alert("登陆失败,用户名或者密码错误!");
location="main.html";
//-->
</script>
<?php
}
?>