php - 即使用户通过单击“后退”注销后,如何避免进入登录 session ?

标签 php mysql

我已经创建了一个登录表单。它工作正常,但如果用户在注销后单击后退按钮,它会返回到登录页面。 当我尝试阻止它时,索引页面停止工作。它显示加载页面错误的问题。

我在索引页面中执行了此操作,以避免用户不返回登录 session ,但现在索引页面本身不起作用。

if (!isset($_SESSION['user'])) {
    header('Location:index.php');
}   

注销.php:

session_start();#This will start the session
session_unset(); #Session_unset and Session_destroy
session_destroy();#Will remove all sessions.

header("location:index.php");#This code will sen du back to the index page

用户登录后,即登录到此主页。我添加了这样的 session :

session_start();

$user = $_SESSION['user'];

有不对的地方请指正。我面临的问题是:

  1. 显示我的索引页
  2. 避免用户在注销后返回登录 session

最佳答案

Follow the Post/Redirect/Get pattern.

Post/Redirect/Get (PRG) is a common design pattern for web developers to help avoid certain duplicate form submissions and allow user agents to behave more intuitively with bookmarks and the refresh button.

When a web form is submitted to a server through an HTTP POST request, a web user that attempts to refresh the server response in certain user agents can cause the contents of the original HTTP POST request to be resubmitted, possibly causing undesired results, such as a duplicate web purchase.

有用的读物​​:

<小时/>

您可以做的最简单的事情就是在 header.php(或共享的类似文件)中放置一个条件:

session_start(); // on top of the scrit
................
...............

if (! isset($_SESSION['yourKey'])){
  header('LOCATION: notLoggedPage.php');
  exit;
}

注意:只要脚本中有与 session 相关的函数,请务必将 session_start() 放在脚本的开头。

关于php - 即使用户通过单击“后退”注销后,如何避免进入登录 session ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8354787/

相关文章:

php - 删除数据库记录 MVC

php - Mysql获取日期为本月的元组

java - MySQL Connector/JDBC 线程安全吗?

php - 对分页的一些误解

c# - vb.net mysql 将文本框的值与表列中的单个值进行比较

PHP Mail、setlocale 和重音字符

php - 显示两个连接表中的数据时如何更改分组?

PHP Excel 图像改变大小

php - 使用join mysql从三个表中获取数据

MySQL已损坏,无法启动: "Restoring possible half-written data pages from the doublewrite buffer..."