2012-01-14 65 views
2

我已经在我的codeigniter应用程序中使用真棒codeigniter authentication library ion auth创建了用户身份验证,身份验证可以正常工作,但是当我注销并单击浏览器的按钮时,我可以浏览我访问过的所有页面引起用户隐私的关注的应用程序,但如果我尝试刷新页面,则认识到我已注销。当用户点击浏览器的返回按钮时,如何强制浏览器重新加载?如何解决这个问题的任何建议将感激..Codeigniter会话问题

编辑

控制器注销功能

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提前..

+0

显示一些代码...我敢打赌,你不检查“被记录在”这就是probly每一页上为什么,只是做在登录时。需要检查您的'安全区域'的每页 – Jakub 2012-01-14 08:14:40

+0

我确实检查了这就是为什么当我重新加载页面时,它会将我重定向到登录页面,它看起来像某人注销时页面不会重新加载 – 2012-01-14 08:20:33

+0

也许您不完全注销,很难说没有任何代码,发布一个典型的控制器设置,因为我从来没有在CI上的会话中遇到过这个问题。 – Jakub 2012-01-14 15:58:32

回答

6

机会是他们实际上注销(如你所说,刷新导致他们出现登出)。浏览器很可能已经缓存了显示的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> 
+0

Thanx很多@Ben Swinburne ..这是缓存问题。我在codeigniter中通过添加'$ this-> output-> set_header(“Cache-Control:no-store,no-cache,must-revalidate,no-transform,max-age = 0,post-check = 0,预检查= 0" ); $ this-> output-> set_header(“Pragma:no-cache”);'在除认证控制器之外的每个控制器的构造函数处。 – 2012-01-15 09:48:30

+0

尝试在控制器级别的数据库交互功能上重定向,而不是禁用缓存。 – serdarsenay 2013-02-20 01:49:00

+0

@SamSamson:我不明白为什么你不会在任何地方缓存除了“身份验证控制器”。我认为每个人都使用会话的ion_auth。所以no-cache在“认证控制器”中也应该没问题。 – neelabh 2015-07-07 15:11:04

1

我非常不鼓励禁用缓存,因为这会降低您的应用程序的速度。我曾因为傻编码的同样的问题,我所做的就是在我的控制器,我把下面的代码在其与数据库交互的每个功能,用户所使用的顶部登录状态:

//Do not let anyone interact with database from cached pages! 
    if (!$this->tank_auth->is_logged_in()) { 
     redirect('/auth/login/'); 
    } 

因此,重定向到登录页面会发生,也就是刷新,如果注销用户的浏览器被“支持”到缓存登录状态并试图摆弄数据库。

0

是离子认证有这个问题我在我的应用程序面临同样的问题。 anothr问题是,如果会话在任何链接上过期,它将使您登录页面。但是当您登录并尝试访问会话过期的最后一个链接时,它总会将您带回登录页面。要访问您需要清除浏览器缓存的页面。这里是解决方案,我在github评论发现离子权威性

github ion-auth comment link

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'); 
}