0

我有一个 jQuery Mobile 网站

  • 它有登录页面,个人资料页面,编辑个人资料页面。
  • 用户可以登录并访问其他页面。
  • 我正在使用 cookie 维护会话,该 cookie 将登录状态保持 30 分钟。当用户在登录以外的任何其他页面时,用户可以通过单击注销按钮注销。注销时 cookie 被删除,用户被重定向到登录页面。
  • 当用户注销并点击返回按钮时,用户将导航到上一个未经授权的页面,因为用户已经注销。

有没有办法阻止用户导航到未经授权的后页?

4

3 回答 3

2

您应该在每个页面的顶部都有服务器端代码,以检查用户是否已登录,如果未登录则重定向。如果退出后后退按钮仍然有效,则意味着浏览器正在显示页面的缓存版本(用户可能无法从那里进一步导航)。

于 2013-01-28T14:10:17.390 回答
0

试试这个简单的脚本:

http://viralpatel.net/blogs/disable-back-button-browser-javascript/

当您尝试返回时,它会重新加载当前页面。

于 2013-01-28T14:05:45.907 回答
0

感谢大家的贡献。我找到了另一种有助于处理反向导航到未经授权页面的方法。我想与大家分享这一点。使用 setInterval 函数我能够知道每一秒的会话可用性。下面是我的带注释的代码。

var userDetails = getUser( );//get the user details from cookie
if(userDetails != null) // if user session exhists
{
if(userDetails.remember == 0){
var IDLE_TIMEOUT = 30 * 60; // set 30 minutes inactive timeout 
var _idleSecondsCounter = 0; // counter to count seconds starts from 0

//extend the session timeout by extending the cookie expiry by 30 minutes if the user is active and set the counter to zero
document.onclick = function() {
        updateCookie();
    _idleSecondsCounter = 0;
};
document.onmousemove = function() {
    updateCookie();
    _idleSecondsCounter = 0;
};
document.onkeypress = function() {
    updateCookie();
    _idleSecondsCounter = 0;
};

//function to check the idle time and 
function CheckIdleTime() {
    _idleSecondsCounter++;
    var curPage = $('.ui-page-active').attr('id');

    if (_idleSecondsCounter >= IDLE_TIMEOUT && curPage != "login")
    {
            delcookie(); //once session timeout occurs delete the cookie
            alert("Session Timeout");
            $.mobile.changePage( "#login", { transition: "slideup", changeHash: true });
    }
}
window.setInterval(CheckIdleTime, 1000);//check idle time every second
}
}else// if user session does not exhists
{
    $.mobile.changePage( "#login", { transition: "slideup", changeHash: true });
}
于 2013-05-16T10:28:52.343 回答