简体   繁体   English

使用HTML和/或Javascript自包含登录

[英]Self contained login using HTML and/or Javascript

I am looking at making an idle game that stores data server side(instead of cookies) and would like a simple way (no mysql or php preferably) to register and login using html5 and/or javascript. 我正在寻找一个存储数据服务器端(而不是cookie)的空闲游戏,并希望使用html5和/或javascript注册和登录一个简单的方法(最好不要使用mysql或php)。 I am VERY new to programming and therefore have no example to show sorry. 我对编程很新,因此没有示例表示抱歉。 any help would be greatly appreciated! 任何帮助将不胜感激!

Disclaimer: I know it is stupid or a sin to answer this kind of question, but it is okay for an absolute beginner. 免责声明:我知道回答这类问题是愚蠢或罪恶的,但绝对是初学者。

You have a lot of contradictory statements. 你有很多矛盾的陈述。 First you said you wanna store it in the server side, but not PHP or MySQL (which is basically one of server side programs). 首先,你说你想把它存储在服务器端,但不是PHP或MySQL(基本上是服务器端程序之一)。

You are confusing Java and JavaScript. 你混淆了Java和JavaScript。 This is like equating Hamburger and Hamburg or Ham? 这就像汉堡和汉堡或火腿等同? Whatever. 随你。 Java is not JavaScript. Java 不是 JavaScript。 Please understand. 敬请谅解。

A solution for you is localStorage and using it, you can store and retrieve data for the particular session, the more or less almost same way how a server session works. localStorage一个解决方案是使用它,您可以存储和检索特定会话的数据,或多或少几乎与服务器会话的工作方式相同。 You can use the following snippet to check if the user is logged in: 您可以使用以下代码段来检查用户是否已登录:

if (typeof Storage !== "undefined") {
  if (localStorage.getItem("user") != null)
    // User is logged in
  else
    // Redirect to login.
}

Please have a look about how to work with localStorage . 请查看如何使用localStorage This is ideal for Games, as they might need to go in and around pages and share information between them. 这是游戏的理想选择,因为他们可能需要进入页面并在页面之间共享信息。

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

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