views:

276

answers:

5

I am trying to implement the functionality that is done by most web applications on the web that have a login screen and a "Remember me" checkbox on the side that if checked will allow open entry to the user next time they visit the web page...As in, it does not ask the user for username and password anymore it just logs them in.

I want to do this using PHP

+10  A: 

It's called a "Remember Me" cookie, which is usually just another cookie that either doesn't expire or has a long (days, weeks, months) expiry to say who you are and is essentially trusted by the site in question.

I would suggest taking a look at PHP: AutoLogin (’Remember Me’) using cookies and Improved Persistent Login Cookie Best Practice.

cletus
A: 

Simple answer is to use cookies. Cookies are small pieces of data stored on the client machine by web pages. Set a cookie when user logs in, check for cookies when the page loads.

Check PHP Cookies tutorial for details.

Amarghosh
A: 

It is called "Session management" mostly implemented by a technique called "HTTP Cookie". In php you can see an excellent tutorial here.

NawaMan
A: 

You use cookies. Cookies are small files that gets stored on the user's machine for a particular website. It contains one value and a expiry date (cookies will automatically be deleted by the browser after x amount of time). So you can save a cookie that contains the user name when they choose the "Remember me" option. When the user returns to the site, check if that cookie exists and what the value is, then log the user in and renew the cookie expiry date.

Stephan Coetzee
+3  A: 

What ever the serverside scripting you can use, the logic relies same.

the following are the step you need to take care.

  1. Add a column to the DB in the UserInfo table "isLoggedIn" as BIT field with default value "FALSE".

  2. When ever user logged into your web application with "Remeber Me" check box checked, set the "isLoggedIn" column remains "True", untill he/she eagerly click on the "SIGN OUT" option of your web application. if he/she click on the "Sign out" option then set the "isLoggedIn" column to "FALSE".

  3. And when ever the user loging in, create the client side cookie for the user. so when the next time page load check the client side cookie, for the user and check the DB column "isLoggedIn" for the same user is "TRUE" if its "True" dont stop the user for login otherwise ask he/she to login.

Hope i am clear, if it confuses you kindly let me know.

Good Luck.

solairaja