<?php
//使用session
//设置session
// session_start();
// $_SESSION['a'] = 'admin';
//设置cookie,如果有cookie,说明用户已经登陆或者cookie在过期时间内,可以进行页面跳转,直接跳转到首页
if($_COOKIE){
header('location:shouye.php');
}
if($_POST){
$uname = trim($_POST['uname']);
$pwd = md5($_POST['pwd']);
if($uname == 'zhangsan' && $pwd == md5('123456')){
//设置cookie值
setcookie('admin','admin',time()+3600);
//跳转页面
header('location:shouye.php');
}else{
echo '账号或密码错误';
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form action="" method="post">
用户名:<input type="text" name="uname" id="">
密码:<input type="password" name="pwd" id="">
<input type="submit" value="提交">
</form>
</body>
</html>
<?php
//session
// session_start();
// var_dump($_SESSION);
//判断cookie值
/*
如果没有cookie值,则说明用户没有登陆,直接跳转到登陆页面
*/
if(!$_COOKIE){
//跳转页面
header('loaction:login1.php');
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
欢迎登陆
</body>
</html>