0

I am creating a user session()(using play framework 2.5.x) after user_name, password matches with entries present in my database.

What I want is user should be logged in for every page he visit in my website, till he signed out himself.

How I can achieve this?

Will I have to write JavaScript to read cookies(session) on every page of my website or any other way.

Thanks..!

Prakash P
  • 3,582
  • 4
  • 38
  • 66

1 Answers1

0

Once the user login to the website, save the username into session or cookies. while accessing each page of your website, read session storage or cookies to check whether the user is logged in or not. if not, prompt the login screen, else proceed with the content.

Once the user logged out of the website, clear the sessionStorage or Cookies.

About Cookies

Session Storage

Sabith
  • 1,628
  • 2
  • 20
  • 38
  • u mean session, cookies set by server can be read by JS? but this way what abt security, any one can change it. – Prakash P Jun 05 '16 at 06:55
  • what will be better to store user details in session or cookie variable – Prakash P Jun 05 '16 at 06:58
  • Security will be a big challenge depending upon your application. Cookie will store your data in browser, however Session will lose data once you close the window, forcing the user to login each time. – Sabith Jun 05 '16 at 08:07
  • I read one can not directly read session using JS as they are stored on server. if one want to access he will have to do server call. Is it true? – Prakash P Jun 05 '16 at 08:09
  • Take a look at http://stackoverflow.com/questions/29986657/global-variable-usage-on-page-reload – Sabith Jun 05 '16 at 08:12