How I do it...
- User submits credentials (username & password) on a login page.
- Action script from the submit form checks the credential against the user DB.
- If they check out, create a session record in the DB (user ID, start time, expire time, session ID, closed flag) and set a cookie with the user ID, session ID and an MD5 hash to make sure nobody is mucking with the cookie client-side.
- At the top of each protected page, I call a function to retrieve the cookie and check it against the session record. If it checks out, it returns the user ID which can then be used to generate custom content. If it doesn't check out they get redirected to the login page.
- To logout, I delete the cookie, and mark the session record as closed. Deleting the cookie client side is not enough.
3 or 4 hours ... if you know the language, web development, etc. probably. For a newb, definitely not. I think when I did this the first time as I was learning PHP it was more like a day or so.