简体   繁体   English

基于Web的页面会话

[英]Web-based page session

I'd like to create a web app where the user is able to create a session, with the session being accessible even after leaving the page/browser. 我想创建一个Web应用程序,使用户能够创建会话,并且即使离开页面/浏览器也可以访问该会话。

An example would be http://lichess.org where the user goes to 'Create a game' and a page is created. 一个示例是http://lichess.org ,其中用户转到“创建游戏”并创建了一个页面。 That page then remains accessible even after the session is finished; 即使会话结束,该页面仍可访问; see: http://en.lichess.org/i8pV0vEv 参见: http : //en.lichess.org/i8pV0vEv

Essentially what I'd like to know is, what would be needed in order to create a similar effect. 从本质上讲,我想知道的是,创建类似效果所需的条件。 I've programmed tonnes over the years, just web environments are new to me! 这些年来,我已经为吨编程了,只是Web环境对我来说是新的! Scala seems like a contender, but in all honesty I have no clue. Scala似乎是一个竞争者,但老实说,我一点都不知道。 Perhaps javascript? 也许JavaScript?

Any advice would be appreciated, thanks. 任何建议,将不胜感激,谢谢。

Web programming is generally session-less and you need a cookie to simulate a session. Web编程通常不需要会话,因此您需要一个cookie来模拟会话。 You save this in your client's browser and in a database to be able to tie them together. 您可以将其保存在客户端的浏览器和数据库中,以便将它们绑定在一起。 Or you can use the browser-session which in the end is also a cookie, but does not scale very well as it's saved in the internal mechanisms of the web-server. 或者,您可以使用浏览器会话,该浏览器会话最终还是cookie,但扩展性不佳,因为它已保存在Web服务器的内部机制中。

There's nothing Scala specific here, but if you would like to give Scala a try, have a look at Play framework . 这里没有特定的Scala,但是如果您想尝试Scala,请看一下Play framework It's pretty beginner friendly and already has built in support for everything you would need like Sessions , Cookies and Database access. 它非常适合初学者,并且已经内置了对您需要的所有内容的支持,例如会话Cookie数据库访问。

If you want to store user session data permanently irrespective of whether user is on the website or not you may use browser storage facility of HTML 5. where you can store data on user's browser in form of key value pair and the data will be there permanently(based on type of browser storage you are using) and you can easily manipulate data using javascript. 如果要永久存储用户会话数据,而不管用户是否在网站上,都可以使用HTML 5的浏览器存储功能。在这里,您可以以键值对的形式在用户浏览器中存储数据,并且数据将永久存在于此。 (基于您使用的浏览器存储类型),您可以轻松地使用javascript处理数据。 There are mainly two types of browser storage. 浏览器存储主要有两种类型。

  • Local Storage : will be there permanently and can be accessed anytime you want. 本地存储 :将永久存在,并且可以随时访问。
  • Session Storage : will be there till the page is open and cleared when user close the browser window. 会话存储 :在用户关闭浏览器窗口之前,页面将一直存在,直到页面被打开和清除。

For your requirement my recommendation is to go for Local Storage 根据您的要求,我的建议是去本地存储

Advantages of Using Local Storage 使用本地存储的优势

  • Can be manipulated easily using JavaScript. 可以使用JavaScript轻松地进行操作。
  • Will be permanent. 将是永久的。
  • No server-side scripting hence, fast to load and manage. 因此,无需服务器端脚本,即可快速加载和管理。

Disadvantages of using local storage 使用本地存储的缺点

  • won't work in browser not supporting HTML5(supported in IE 8,chrome 4,Mozilla 3.5,safari 4,opera 11.5 and above) 在不支持HTML5的浏览器中将无法使用(IE 8,chrome 4,Mozilla 3.5,Safari 4,opera 11.5及更高版本支持)
  • User will be able to manipulate/delete the value(The browser storage value can be manipulated using resource option of Browser developer tool) 用户将可以操纵/删除值(可以使用浏览器开发人员工具的资源选项操纵浏览器存储值)
  • Wont be permanent if user is visiting in In-cognito/in-private mode.(but will be stored during the session.) 如果用户以隐身/私密模式访问,则不会永久保存(但将在会话期间存储)。
  • Data limit of at least 5MB 数据限制至少为5MB
  • Data will be deleted when user clears browser history. 用户清除浏览器历史记录后,数据将被删除。

for further reference checkout w3schoold http://www.w3schools.com/html/html5_webstorage.asp 有关更多参考,请查看w3schoold http://www.w3schools.com/html/html5_webstorage.asp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM