<?php
session_start();//使用session必须
if(!empty ($_SESSION['name'])){
    echo '您已经登录了';
    header("Location:index.php");//检测如果session为真,则转到系统后台首页!
}
require 'conn/dbconnect.php';
?><!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" />
<meta name="robots" content="ALL" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<title></title>
<link rel="stylesheet"  type="text/css" href="./style/css/style.css" />
</head>
    <body>
     <?php        if($_GET['action']=='login'){
            //清除空格
            $_POST['name'] = trim($_POST['name']);
    $_POST['password'] = trim($_POST['password']);        if(!$_POST['name'] || !$_POST['password']){
            //判断用户名和密码是否都填写
            echo "用户名和密码不能为空";
            exit();
        }
        if (!get_magic_quotes_gpc()) {// 如果魔术引号关闭使用addslashes转换
$_POST['name'] = addslashes($_POST['name']);
}        //判断用户信息
       $q = $query->query('select id_num,name from users where name=\''.$_POST['name'].'\' and password=\''.md5($_POST['password']).'\'');
       $rs = $query->fetch_array($q);
if (!$rs['id_num']) {
echo '用户信息填写错误!<br>';
exit();
}
        // 注册session变量
$_SESSION['id_num'] = $rs['id_num'];
$_SESSION['name'] = $rs['name'];
header("Location:index.php");
       //检测如果session为真,则转到系统后台首页!
exit;
           }
        ?>
        <div class="login_window">
            <form action="login.php?action=login" method="post" name="form_login" id="form_login">
                <div class="login_name form_line">用 户:<input type="text" name="name" class="name" value=""  /></div>
                <div class="login_password form_line">密 码:<input type="password" name="password" class="password" value="" /></div>
                <div class="login_selection form_line">选 项:<input type="radio" name="selection" value="教师" checked="true" />教师 <input type="radio" name="selection" value="学生" />学生</div>
                <div class="login_idcode form_line">验证码:<input type="text" name="idcode" class="idcode" value="" /><img /><a href="">换一张</a></div>
                <div class="login_btn"><input type="submit" value="登录" /> <input type="reset" value="取消" /></div>
            </form>
           </div>
        <div class="footer auto_width"><?=$tms_notice?></div>
    </body></html>