我可以在javascript中保存客户端状态吗?(Can I save client side state in javascript?)

编程入门 行业动态 更新时间:2024-10-03 14:32:37
我可以在javascript中保存客户端状态吗?(Can I save client side state in javascript?)

我有几个网页只有在某些条件成立时才能工作。 例如,有一个注册页面,一个登录页面。 如果有人已登录,我不希望用户再次登录或再次注册,直到他退出。 目前,服务器将登录保存在SESSION变量中,并且每个网页都必须调用服务器以获取SESSION变量并确定是否显示该页面。 这似乎不是一个好的解决方案。 我在想可能是在客户端保存,但我不知道一个好的方法。 我应该使用cookie吗? 客户端是否还有其他一些服务来存储会话数据?

I have several web pages that should work only if certain condition is true. For example, there is a registration page, a login page. If someone is already logged in, I don't want the user to login again or register again until he is logged out. Currently the server saves the login in a SESSION variable and each web page has to called the server to get the SESSION variable and determine whether to display the page or not. This does not seem like a good solution. I am thinking may be saving in on the client side, but I don't know a good approach. Should I use cookie for this ? Is there some other services on the client side to store session data ?

最满意答案

Cookie是涉及登录的会话详细信息的最佳选择,任何其他持久存储应使用localStorage。

这是因为cookie将在每个请求时传输到服务器,因此可用于验证每个调用。

如果你对这类东西感到困惑,那对你的网站来说可能是非常危险的。 尝试阅读它并尝试使用您的语言/框架/库的标准。

Cookies are the best option for session details involving login, any other persistent storage should use localStorage.

This is because cookies will be transferred to the server on each request and therefore can be used to authenticate each call.

If your confused about this sort of stuff it can be very dangerous for your site. Try read up on it and try to use whatever the standard is for your language/framework/library.

更多推荐

本文发布于:2023-07-09 10:15:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1085579.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:客户端   状态   javascript   save   state

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!