简体   繁体   English

用javascript模拟用户会话

[英]Simulate User session with javascript

When a user visits below login screen and provides any user name and password, they should be considered a "logged in" user if they go to any subsequent pages without closing their browser. 当用户在登录屏幕下方访问并提供任何用户名和密码时,如果他们在不关闭浏览器的情况下转到任何后续页面,则应将其视为“登录”用户。

<html>
<form action="" method="POST">
<span>Login:</span><input type="text" name="puname" ><br>
<span>Password:</span><input type="text" name="ppasswd"><br>
<input type="submit" value="Register"/>
</form>
</body>
</html>

Can anyone suggest how I can implement this with JavaScript (perhaps using cookies)? 谁能建议我如何使用JavaScript(也许使用cookie)实现这一点?

Cookies are the way to go, you can then make the decision if you want them destroyed at browser close, or destroyed after set time(ie 1 day). Cookies是一种解决方法,如果您希望它们在浏览器关闭时销毁,或者在设定的时间(即1天)后销毁,则可以做出决定。 If your not apposed to jquery, this plugin makes it very simple https://github.com/carhartl/jquery-cookie 如果您不喜欢jquery,此插件将使其变得非常简单https://github.com/carhartl/jquery-cookie

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

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