博主信息
JiaJieChen
博文
63
粉丝
3
评论
5
访问量
42718
积分:0
P豆:128

PHP:【商城后台管理系统】部署管理员未登录拦截,进行重定向

2021年06月10日 13:04:57阅读数:297博客 / JiaJieChen/ ThinkPHP6.0商城项目

PHP:【商城后台管理系统】部署管理员未登录拦截,进行重定向

一.未登录拦截界面

二.部署流程

  1. 部署流程
    • thinkphp:使用thinkphp6.0 BaseController 里面的初始化控件进行重定向拦截,我们在管理员登陆成功后会进行存储session,然后我们进行判断session里面是否有用户的存储信息,如果没有则进行重定向到登录页面,如果有用户信息则返回json格式给前端

HTML 代码块

  1. exit('<!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title></title>
  6. <style>
  7. html,body{height:100vh}
  8. html:before,html:after,body:before,body:after{content:&#x27;&#x27;;background:linear-gradient(#203075,#233581);border-radius:50%;position:absolute;top:50%;left:50%;transform:translate(-50%,-50%)}
  9. html:before,body:before{background:linear-gradient(#233581,#203075)}
  10. html{background:linear-gradient(#203075,#233581);overflow:hidden}
  11. html:before{height:105vmax;width:105vmax;z-index:-4}
  12. html:after{height:80vmax;width:80vmax;z-index:-3}
  13. body{display:flex;justify-content:center;align-items:center;color:#FFF;font-family:&#x27;Varela Round&#x27;,Sans-serif;text-shadow:0 30px 10px rgba(0,0,0,0.15)}
  14. body:before{height:60vmax;width:60vmax;z-index:-2}
  15. body:after{height:40vmax;width:40vmax;z-index:-1}
  16. .main{text-align:center;z-index:5}
  17. p{font-size:18px;margin-top:0}
  18. h1{font-size:145px;margin:0}
  19. button{background:linear-gradient(#EC5DC1,#D61A6F);padding:0 12px;border:none;border-radius:20px;box-shadow:0 30px 15px rgba(0,0,0,0.15);outline:none;color:#FFF;font:400 16px/2.5 Nunito,&#x27;Varela Round&#x27;,Sans-serif;text-transform:uppercase;cursor:pointer}
  20. .bubble{background:linear-gradient(#EC5DC1,#D61A6F);border-radius:50%;box-shadow:0 30px 15px rgba(0,0,0,0.15);position:absolute}
  21. .bubble:before,.bubble:after{content:&#x27;&#x27;;background:linear-gradient(#EC5DC1,#D61A6F);border-radius:50%;box-shadow:0 30px 15px rgba(0,0,0,0.15);position:absolute}
  22. .bubble:nth-child(1){top:15vh;left:15vw;height:22vmin;width:22vmin}
  23. .bubble:nth-child(1):before{width:13vmin;height:13vmin;bottom:-25vh;right:-10vmin}
  24. .bubble:nth-child(2){top:20vh;left:38vw;height:10vmin;width:10vmin}
  25. .bubble:nth-child(2):before{width:5vmin;height:5vmin;bottom:-10vh;left:-8vmin}
  26. .bubble:nth-child(3){top:12vh;right:30vw;height:13vmin;width:13vmin}
  27. .bubble:nth-child(3):before{width:3vmin;height:3vmin;bottom:-15vh;left:-18vmin;z-index:6}
  28. .bubble:nth-child(4){top:25vh;right:18vw;height:18vmin;width:18vmin}
  29. .bubble:nth-child(4):before{width:7vmin;height:7vmin;bottom:-10vmin;left:-15vmin}
  30. .bubble:nth-child(5){top:60vh;right:18vw;height:28vmin;width:28vmin}
  31. .bubble:nth-child(5):before{width:10vmin;height:10vmin;bottom:5vmin;left:-25vmin}</style>
  32. </head>
  33. <body>
  34. <div class="bubble"></div>
  35. <div class="bubble"></div>
  36. <div class="bubble"></div>
  37. <div class="bubble"></div>
  38. <div class="bubble"></div>
  39. <div class="main">
  40. <h1>404</h1>
  41. <h2>Error</h2>
  42. <p>您未登录,请您登录!</p>
  43. </div>
  44. </body>
  45. </html>
  46. <script>
  47. setTimeout(()=>{
  48. window.location.href="/admin/Account/login";
  49. },1500)
  50. </script>

PHP 代码块

  1. <?php
  2. namespace app\admin\controller;
  3. use app\BaseController;
  4. use think\facade\Request;
  5. use think\facade\Db;
  6. use think\facade\View;
  7. use think\facade\Session;
  8. /**
  9. * 后台基础控制器
  10. */
  11. class Base extends BaseController
  12. {
  13. //未登录拦截
  14. protected function initialize()
  15. {
  16. $admin = Session::get('admin');
  17. if ($admin) {
  18. if (Request::isAjax()) {
  19. $id = (int)Request::param('otuLogin');
  20. if ($id == 0) {
  21. echo json_encode(['id' => 1 , 'msg' => '退出登录成功']);
  22. return;
  23. }else {
  24. echo json_encode(['id' => 0 , 'msg' => '用户已登录']);
  25. return;
  26. }
  27. }
  28. }else {}

版权申明:本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!

全部评论

文明上网理性发言,请遵守新闻评论服务协议

条评论