1、登录login.php 用户admin密码123456
<?php
session_start();
if (isset($_POST['user'])) {
$user = $_POST['user'];
$password = $_POST['password'];
if ($user == 'admin' && $password == '123456') {//验证正确
$_SESSION['user'] = $user;
//跳转到首页
header('location:index.php');
}else{
echo "<script>alert('登录失败,用户名或密码不正确');</script>";
exit();
}
}
?>
<script type='syntaxhighlighter' class='brush: html '>
<form method="POST">
用户名: <input type="text" name="user"><br />
密码: <input type="text" name="password"><br />
<input type="submit" value="提交">
</form>
?复制代码
2、登录成功后index.php
<?php
session_start();
if (isset($_SESSION['user']) && !empty($_SESSION['user'])) {
echo "登录成功:".$_SESSION['user'];
echo "<a href='logout.php'>注销</a>";
}else{
echo "你还没有登录,<a href='login.php'>请登录</a>";
}
?复制代码
3、注销处理界面logout.php
<?php
session_start();
header('Content-type:text/html;charset=utf-8');
if(isset($_SESSION['username']) && $_SESSION['username']==='admin'){
session_unset();//free all session variable
session_destroy();//销毁一个会话中的全部数据
setcookie(session_name(),'',time()-3600);//销毁与客户端的卡号
header('location:skip.php?url=index.php&info=注销成功,正在跳转!');
}else{
header('location:skip.php?url=index.php&info=注销失败,请稍后重试!');
}
?>
?复制代码
4、跳转处理页面skip.php
<?php
if(!isset($_GET['url']) || !isset($_GET['info'])){
exit();
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="refresh" content="1"; url=login.php">
<title>正在跳转中...</title>
</head>
<body >
<div><?php echo $_GET['info'] ?></div>
</body>
</html>
本文链接:https://www.kinber.cn/post/4923.html 转载需授权!
推荐本站淘宝优惠价购买喜欢的宝贝: