Jump to content

Remember me cookies


Xtremer360

Recommended Posts

Time to ask a stupid question. I have a remember me cookie being set for my login page but I'm wondering what I need to do so that the next time the user comes back to the login page it already has the checkbox checked and the username in the username field which is the cookie.

 

Link to comment
https://forums.phpfreaks.com/topic/258056-remember-me-cookies/
Share on other sites

It depends on requirement, if cookie is set then user will be directly logged in without login screen or else you can come to login page and fill the login screen using cookie data, so that user can use same login details or can change it and submit the form. May this will help u

Link to comment
https://forums.phpfreaks.com/topic/258056-remember-me-cookies/#findComment-1322997
Share on other sites

It depends on requirement, if cookie is set then user will be directly logged in without login screen or else you can come to login page and fill the login screen using cookie data, so that user can use same login details or can change it and submit the form. May this will help u

 

Um, if the cookie is set than the cookie is set, that is all.  Only if the script is built to log the user in IF a cookie is set, will it log a user in automatically.

 

Time to ask a stupid question. I have a remember me cookie being set for my login page but I'm wondering what I need to do so that the next time the user comes back to the login page it already has the checkbox checked and the username in the username field which is the cookie.

 

You need to make an if statement to produce the appropriate html to render what you need.

<?php
if ( isset ( $_COOKIE['username'] ) )
{
   $preparedUsername = ' value=' . $_COOKIE['username'] . '';
   $rememberMe = ' checked';
}
print '<input type="text" name="username"'.$preparedUsername.'><br />';
print '<input type="checkbox"'.$rememberMe.'>';

 

I'm assuming if a user does not check remember me than a cookie is not set and sessions are used instead and vice versa. That is why I only checked to make sure that there is a cookie set to know if we should keep the box checked.

 

I personally feel doing it this way is a drag, if you are to check a box that says remember me you would it expect it to automatically log you in on the next visit.  I'd only do it your way if this was a bank or other type of business that handles money, credit cards, etc.

 

 

Link to comment
https://forums.phpfreaks.com/topic/258056-remember-me-cookies/#findComment-1323029
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.