【发布时间】:2014-11-22 02:42:47
【问题描述】:
当用户决定退出时,他们显然是通过使用“退出”按钮来完成的。
当他们这样做时,将执行此脚本:
if(isset($_POST['submit_Logout'])){
$_SESSION['backend']->logout(); // see this function bellow
unset($_SESSION['user']); // unset only this session since there are other sessions I'd like to keep
session_regenerate_id(true); // makes sure the session id is updated, and the old one is discarded
KD::notice('success',$success_LoggedOut); // adding a notice to another session
KD::redirect('/'); // redirecting the user using header();
session_commit();
}
我只是取消设置此特定会话 (user),因为有其他会话可以保持其他数据可用,无论用户是否登录,以改善用户体验。
logout()-函数现在看起来像这样:
public function logout(){
$this->accessible=false; // just a flag to check against (see bellow)
$this->username=''; // empty the username
}
由于我正在取消设置保存相关用户数据的会话,我才意识到这个功能可能是不必要的。或者将未设置的部分等移动到函数中..
无论如何,我已经体验到,当用户注销时,他/她或其他人有机会只需点击浏览器中的后退按钮,瞧,他们可以查看页。当然,如果他们开始点击任何链接,他们就会被淘汰。但是后退按钮仍然可用..
我相信这是由于浏览器缓存页面/视图的结果。因此,当他们单击后退按钮时,他们会看到存储在浏览器内存中的缓存页面/视图或其他内容..
由于此页面或视图通过 index.php 页面加载到我的模板中,并带有永久的<head>,因此对于这些受限页面/视图的缓存我无能为力。或者有吗?
无法从浏览器历史记录中删除记录?还是从一开始就阻止这些页面被记录?
点是。我相信,我需要做的是强制浏览器始终从服务器请求页面。因此,无论用户是否点击后退按钮或指向受限页面的链接,该页面都应始终从服务器请求它,而不是浏览器内存..
还是我没有理解正确?
如果是这样。我很想知道怎么做。这通常是怎么做的?
我班上有这个
private $accessible = false; // when logged in, this is set to true
public function accessible(){
return $this->accessible;
}
在包含进入限制区域的视图的页面的最顶部,我有这个:
if($_SESSION['user']->accessible()===true):
否则,系统会通过登录屏幕提示用户。
但这并没有按预期工作。当用户在浏览器中使用后退按钮时,不会执行此检查...
提前谢谢..
更新
下面是我的结构/布局的快速概述:
/*
when the user is logged in/out, the script that does that is executed up here.
That includes setting the sessions etc. aswell - which means, if the user is not logged in, the access will be set to false.
*/
<head>
</head>
<body>
/*
Here I include different pages with php include;
These pages can be home.pg.php, contact.pg.php, and of course restricted.pg.php
each of these pages includes different content (views as I like to call them) that is presented to the user based on their interaction.
Now. When the user tries to access the restricted.pg.php, I have this at the top:
*/
if($_SESSION['user']->accessible()===true):
/* now each view that is included here should be not accessable if accessable() is not true. */
else:
/* the user is presented with a login form */
endif;
</body>
这有帮助吗?
【问题讨论】:
-
注销后是否有header重定向?
-
是的。
KD::redirect('/')是header('Location:/')(在这种情况下)。我正在为这个问题添加一些 cmets... -
我不明白那行,也许你需要先进行会话提交,然后再进行重定向,这是最合乎逻辑的事情,做你需要做的一切,然后最后,重定向
-
你的问题的答案大概是here。