php - How to safely manage connected user -
i think figure dout how this:
when user connect, after checking if has username/password, session key (a random long string) created , put inside db. same session_key put inside session.
if user out of app without login off, when comes back, if session_key match 1 in db, user o.k , connect user have session_key. if not, session closed, user rerouted login. if there's no problem, new session_key created (to replace old one).
i think o.k., except 2 things:
-how can make session_key disappear db after time? guess should execute code on server, how can execute code on server if nobody using app moment?
-if it's session_key, alright use cookie insted?
-is o.k. check if there's session_key in db correspond session_key in session, or should use else sure? generate random long string , crypt same way password, think secured enough , wouldn't session_key identical.
-insteed of using username data db, o.k. use session_key (getstuffbysessionkey())?
what if user access cookie , change username?
there's no need store username in cookie. cookie should only have session key info. you'll username via db query when user attempts login. if user changes session key value in cookie, no longer match active session in database, , have log in. it's same clearing cookie.
in addition username , session_key, put user privileges in cookie. need know if user admin, creator or visitor.
these should stored in database well, not in cookie.
is there other way check if user didn't try change while still on app?
nope, should checking valid, active session on every request user. if there's no session cookie, or if cookie doesn't match valid session, redirect them login page.
as others have pointed out, you'd wise use php's built-in sessions this.
Comments
Post a Comment