我有一个jQuery Mobile网站
我们是否有办法阻止用户导航到未经授权的后页?
答案 0 :(得分:2)
您应该在每个页面的顶部都有服务器端代码来检查用户是否已登录,如果不是,则重定向。如果后退按钮在注销后仍然有效,则表示浏览器正在显示页面的缓存版本(可能用户无法从那里进一步导航)。
答案 1 :(得分:0)
答案 2 :(得分: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 });
}