一、用户登录界面
<html>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title>学生综合评分系统</title>
<body>
<div id="formbackground" style="position:absolute; width:100%; height:100%; z-index:-2"><img src="1.png" height="100%" width="100%"/></div>
<body>
<form action="logincheck.php" method="post">
<div id=content style="position:absolute;">
<table align="center">
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<tr>
<td>                                                                                                 用户名</td>
<td><input type="text" name="username" ></td>
</tr>
<tr>
<td>                                                                                                 密 码</td>
<td><input type="password" name="password" ></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="login_student" value="学生登录">   <input type="submit" name="login_teacher" value="教师登录"></td>
</tr>
</div>
</form>
<?php
?>
</body>
</html>
二、后台处理
<?php
session_start();
header("Content-Type:text/html;charset=gbk");
//isset检测变量是否被设置,最好使用上,可以不使用他的。
//学生登录
if(isset($_POST["login_student"]) && $_POST["login_student"] =="学生登录"){
$user = $_POST["username"];
$psw = $_POST["password"];
if($user == "" || $psw == ""){
//alert是警告的意思。这句的主要做用就是弹出警告,返回上一页。
echo "<script LANGUAGE='javascript'>alert('请输入用户名或密码!'); history.go(-1);</script>"; //弹出提示框返回上一
}else{
$con=mysql_connect("localhost","root","9277");
mysql_select_db("School",$con);
mysql_query("set names 'gbk'");
$result=mysql_query("select * from Student where Username ='$user' ");//mysql_query 查询数据库的函数
while($row=mysql_fetch_array($result)){
if($row[3]==""){//用户不存在
echo "<script LANGUAGE='javascript'>alert('user is not exit'); history.go(-1);</script>"; //弹出提示框返回上一页
}else if($row[4]!=$psw){
echo "<script LANGUAGE='javascript'>alert('password is wrong'); history.go(-1);</script>"; //弹出提示框返回上一页
}else{
$_SESSION["Student_Name"]=$row[1];//页面显示登录人的姓名。
$_SESSION["username"]=$row[3];
$_SESSION["Student_ID"]=$row[0];
$_SESSION["Student_Class"]=$row[2];
if($row[5]=="A"){
header("Location: http://192.168.116.128/school/studentA/exam/exam.php");//跳转到这个界面。
}else if($row[5]=="B"){
header("Location: http://192.168.116.128/school/studentB/exam/exam.php");//跳转到这个界面。
}else if($row[5]=="C"){
header("Location: http://192.168.116.128/school/studentC/exam/exam.php");//跳转到这个界面。
}
}
}
}
}
if(isset($_POST["login_teacher"]) && $_POST["login_teacher"] =="教师登录"){
$user = $_POST["username"];
$psw = $_POST["password"];
if($user == "" || $psw == ""){
//alert是警告的意思。这句的主要做用就是弹出警告,返回上一页。
echo "<script LANGUAGE='javascript'>alert('请输入用户名或密码!'); history.go(-1);</script>"; //弹出提示框返回上一
}else{
$con=mysql_connect("localhost","root","9277");
mysql_select_db("School",$con);
mysql_query("set names 'gbk'");
$result=mysql_query("select * from Teacher where Username ='$user' ");//mysql_query 查询数据库的函数
while($row=mysql_fetch_array($result)){
if($row[2]==""){
echo "<script LANGUAGE='javascript'>alert('user is not exit'); history.go(-1);</script>"; //弹出提示框返回上一页
}else if($row[3]!=$psw){
echo "<script LANGUAGE='javascript'>alert('password is wrong'); history.go(-1);</script>"; //弹出提示框返回上一页
}else{
$_SESSION["teacher_Name"]=$row[0];//页面显示登录教师的姓名。
$_SESSION["teacher_Class"]=$row[4];
header("Location: http://192.168.116.128/school/teacher/exam/exam.php");
}
}
}
}
?>