简单的登录回路

index.php文件代码

<?php
include("check.php");
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>后台首页</title>
</head>
<body>
	<?php echo "欢迎您:".$_SESSION['username'];?><a href="loginout.php">注销</a>
</body>
</html>


login.php文件代码

<?php
include("conn.php");
if($_POST['username']&&$_POST['psd']){	
	$sql="select * from user where username='".$_POST['username']."' and psd='".$_POST['psd']."'";
	$result=mysqli_query($conn,$sql);
	$row=mysqli_fetch_array($result);
	if($row['username']){
		$_SESSION['username']=$row['username'];
		header("location:index.php");
	}else{
		echo "登录失败";
	}
}else{
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="http://www.niuguwen.com/plugin/niuguwen/css/niuguwen.css">
<title>用户登录</title>
</head>
<body>
<div class="ngwlogin">
    <div class="formtitle">
        <a href="/">人才管理系统</a>
    </div>
    <div class="ngwform formbody">
        <form class="form" action="login.php" method="post">
            <div>
                <label>用户名</label>
                <input type="text" name="username" placeholder="请输入用户名(学号或手机号)" required="required" class="input" value="" />
            </div>
            <div>
                <label>密码</label>
                <input type="password" name="psd" placeholder="请输入密码" required="required" class="input" value="" />
            </div>
            <ul>
                <li class="fl"><button type="submit">登录</button></li>
                <li class="fr">
                    <a href="register.php">注册</a> 
                </li>
            </ul>
        </form>
    </div>
    <div class="formfoot"></div>
</div>
</body>
</html>
<?php
}?>


conn.php文件代码

<?php
session_start();
$conn=@mysqli_connect("localhost","root","root","rencai") or die("无法连接数据库");	
?>


check.php文件代码

<?php
include("conn.php");
if($_SESSION['username']){
	
}else{
	header("location:login.php");
}
?>


loginout.php文件代码

<?php
session_destroy();
header("location:login.php")
?>


文章导航