[英]Codeigniter session problems
我已经在我的codeigniter应用程序中使用了很棒的codeigniter身份验证库ion auth创建了用户身份验证 ,身份验证工作正常,但是当我注销并单击浏览器的后退按钮时,我可以浏览我在应用程序中访问过的所有页面,引起关注的平均用户隐私,但是如果我尝试刷新页面,它会识别出我已注销。 当用户单击浏览器的后退按钮时,如何强制浏览器重新加载? 关于如何解决此问题的任何建议将不胜感激。
编辑
控制器注销功能
function logout() {
//log the user out
$logout = $this->ion_auth->logout();
//redirect them back to the page they came from
redirect('auth', 'refresh');
}
这是来自ion auth的注销功能
public function logout() {
$this->ci->ion_auth_model->trigger_events('logout');
$identity = $this->ci->config->item('identity', 'ion_auth');
$this->ci->session->unset_userdata($identity);
$this->ci->session->unset_userdata('group');
$this->ci->session->unset_userdata('id');
$this->ci->session->unset_userdata('user_id');
//delete the remember me cookies if they exist
if (get_cookie('identity')) {
delete_cookie('identity');
}
if (get_cookie('remember_code')) {
delete_cookie('remember_code');
}
$this->ci->session->sess_destroy();
$this->set_message('logout_successful');
return TRUE;
}
我正在使用Codeigniter 2.0.3
Thanx提前..
实际上它们很可能已注销(如您所说,刷新会使它们显示为注销)。 浏览器可能已经缓存了显示的HTML,该HTML表明它们已登录,但在注销后不会重新加载它。
您可以通过设置Cache-Control
标头将具有登录相关信息的页面设置为不缓存。
这可以用HTML来实现
<META Http-Equiv="Cache-Control" Content="no-cache">
<META Http-Equiv="Pragma" Content="no-cache">
<META Http-Equiv="Expires" Content="0">
或PHP
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
您还可以使用以下代码来实现对特定窗口的用户历史记录的恶意删除和不明智的清除。 这将需要作为注销功能的一部分发送到浏览器,并且如果用户禁用了javascript,则将无法使用。
<script language="javascript">
var Backlen=history.length;
history.go(-Backlen);
window.location.href=page url
</SCRIPT>
我强烈建议您禁用缓存,因为这会降低应用程序的速度。 由于存在愚蠢的编码,我遇到了同样的问题,我的工作是在控制器中进行的,我将以下代码放在与数据库交互的每个函数的顶部,供处于登录状态的用户使用:
//Do not let anyone interact with database from cached pages!
if (!$this->tank_auth->is_logged_in()) {
redirect('/auth/login/');
}
因此,如果登录用户的浏览器被“备份”到缓存的登录状态并试图摆弄数据库,则会发生重定向到登录页面的情况,这也意味着刷新。
是的,ion auth存在此问题,我在应用程序中遇到了同样的问题。 另一个问题是,如果会话在任何链接上到期,它将带您进入登录页面。 但是,当您登录并尝试访问会话已过期的最后一个链接时,它总是带您返回登录页面。 要访问该页面,您需要清除浏览器缓存。 这是我在github上找到的解决方案关于ion auth的评论
function logout() {
//log the user out
$logout = $this->ion_auth->logout();
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Wed, 4 Jul 2012 05:00:00 GMT"); // Date in the past
//redirect them back to the page they came from
redirect('auth', 'refresh');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.