0

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)?

2
  • You can use cookies or session storage: www.w3schools.com/Html/html5_webstorage.asp. but I think session storage works tab by tab Commented May 18, 2015 at 21:35
  • Are you using a server-side language? Take a look at sessions, or just a simple google search Commented May 18, 2015 at 22:33

1 Answer 1

3

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(i.e. 1 day). If your not apposed to jquery, this plugin makes it very simple https://github.com/carhartl/jquery-cookie

Sign up to request clarification or add additional context in comments.

3 Comments

jquery is probably the easiest way to do this. The native JS methods aren't difficult to grasp though. Check out quirksmode.org/js/cookies.html The hardest part is the expiration, and in this case, for a prototype, if you don't set an expiration at all it'll delete when you close the browser.
How can I get the cookie to get created when they click the 'submit' button on the login form? Do I need to call the JS on the action of the form or the onclick of the submit button? Some examples would be appreciated.
You need to intercept the submit and run your set cookie. Try this stackoverflow.com/questions/19731265/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.