Topic: Sessions & Cookies
I'm constructin a user-login-system that will contain both sessions (for carrying info between pages) and cookies (to allow a user to remeber login).
Now, since i'm gonna use both, i want to authenticate the user if a cookie is present, and redirect to a loginpage if cookie is not valid.
I want to use sessions to "remember" the authenticated user, so i don't have to verify the user on each page-view, but rather compare a session-value with some value in the cookie, and as long as they are in agreement, another authentication against db does not occur.
The sessions will also remember login-status for the duration of the visit if the visitor doesn't want to store a cookie on the computer (The stupid swedish law)
I pretty much will have these functions to do the work for me:
requireMemberStatus - For pages that require member-status or above.
requireAdminStatus - For pages that require admin-status and not available for regular members.
setSessionHandler - First time the session is set with info
updateSessionHandler - The session gets updated with info
destroySessionHandler - When the user logs out (ie, from a public pc for instance)
setCookieHandler - Create the cookie if the user wants to
updateCookieHandler - Update expiretime and session-info on each "verify"
destroyCookieHandler - nuke the cookie
doLogin - Verify the user against the db
doVerify - Validates the cookie and updates the session and cookie
doLogout - Clear up everything...
checkStatus - Checks to see if the user is authenticated, member or admin (return 0, 1, 2)
Now to my problem...
I'm not entierly sure how to make this work as i haven't worked with cookies before and don't quite know how to make a secure varify/auth of the cookie...
Also, what happens with the cookie-authentication/validity if the user is changing computer regulary, like home-machine/work-machine and gets new sessionid's etc between visits?
Ideas, comments etc is welcome...