Blogger Information
Blog 53
fans 3
comment 0
visits 46755
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
cookie和session-第九期线上班
emagic
Original
594 people have browsed it

11月22日作业:

1. SESSION 登录实战

index.php

  1. <?php
  2. //开启会话
  3. session_start();
  4. // 为简化程序, 使用了一个中间层: 请求派发器,类似于框架的控制器, 对用户的请求进行集中处理
  5. // 1: 已登录: 显示出用户的登录信息, 显示退出按钮
  6. if (isset($_SESSION['name'])) {
  7. echo '用户: ' . $_SESSION['name'] . '已登录<br>';
  8. echo '<a href="dispatch.php?action=logout">退出</a>';
  9. } else {
  10. // 2. 未登录,就跳转到登录页面
  11. echo '<a href="dispatch.php?action=login">请登录</a>';
  12. }
  13. ?>

dispath.php

  1. // 只需要在该脚本中打开会话即可, check.php/logout.php/login.php都是由它调用的, 不必重复开启
  2. session_start();
  3. // 连接数据库
  4. require __DIR__ . '/connect.php';
  5. // 获取请求参数
  6. $action = isset($_GET['action']) ? $_GET['action'] : 'login';
  7. $action = htmlentities(strtolower(trim($action)));
  8. // 请求分发
  9. switch ($action) {
  10. // 1. 登录页面
  11. case 'login':
  12. // 加载登录表单
  13. include __DIR__ . '/login.php';
  14. break;
  15. // 2. 验证登录
  16. case 'check':
  17. include __DIR__ . '/check.php';
  18. break;
  19. // 3. 退出登录
  20. case 'logout':
  21. include __DIR__ . '/logout.php';
  22. break;
  23. // 默认操作
  24. default:
  25. header('Location: index.php');
  26. echo '<script>location.assign("index.php");</script>';
  27. }

2. 练熟pdo操作,增删查改(手写)


Correcting teacher:查无此人查无此人

Correction status:qualified

Teacher's comments:完成的不错,继续加油。
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post