views:

71

answers:

2

As the title implies, the automatically login system is wildly used by many websites. But I could not figure it out by myself. Could you please give me some hint.

EDIT: Yes, I mean the remeber me feature like google.

thanks.

A: 

When a user logs in you simply have php create a cookie stating wich user is logged in at that computer. The cookie will remain for as long as you want it to, so this is equivelant of checking a box with "keep me logged in". If you need them to re-login everytime replace the cookie by a session-variable. A user stays in the session as long as he stays on the website.

So depending on the checkbox's setting php will decide whether to use sessions or cookies.

I hope this is what you wanted to know.

Rakward
You're confusing sessions and cookies. A session is a server-side construct to keep per-user settings between page requests. The cookie is used to identify the user and restore the user's settings from the stored session. You can implement session without cookies, and cookies do not imply sessions are being used.
Marc B
+1  A: 

"Remember me" type logins on a site are very simple to implement. There's nothing magical about it. The two major changes are:

  1. Toggling "remember me" to on sets a permanent session cookie instead of a temporary one
  2. The server-side session is not automatically cleaned up/garbage collected for a fixed period (e.g. "Remember me for 30 days" means the login part of the session stays around for 30days).
Marc B