开发者

Adding expiry time in javascript

I want to know how to add logout feature af开发者_高级运维ter certain expiry time in javascript. Can somenody please tell me how to do this. Thanks


Here's an idea you could use:

  1. Add a "Last Seen" column to your User table. Update this value to the current timestamp whenever the authenticated user requests a page.
  2. On the server, whenever a page is requested that requires a login, check to see if the current time is within a given threshold of the "Last Seen" time. If it isn't show the login page.
  3. In addition to this, use setTimeout and AJAX in Javascript to query the server after the threshold amount of time has elapsed. Based on the response, either destroy the session and redirect to the login page, or do nothing.


Add a timeout with setTimeout(). Note that it's trivial to remove such a timer for a cracker, so it's more of a comfort than a security feature.

If security is your concern, you must do this on the server side.

If your question is "how can I logout from, say, GMail", the solution is probably to add some JavaScript to the page with Greasemonkey and assign the URL which you can find behind the "logout" link to window.location.href


This article explains how to use JavaScript and server side code (ASP.Net) to either log the user out or warn them that their session is going to expire. I've implemented something similar to this in an e-commerce application. It seems to work well.

http://blog.oscarscode.com/dot-net/display-session-timeout-warning-with-asp-net-ajax/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜