Page 1 of 1
how to activate remember me checkbox
Posted: Thu Nov 09, 2006 12:32 am
by mang
In the login section there are three fields like
USERNAME :
PASSWORD :
checkbox : Remember me :- How do i work on this checkbox ? I want to do the functionality Remember me on this computer
How it can be done using php code can u suggest any code plz..Once user check the checkbox at the time of login he should be provided with his user name afterwords when he again comes to log in to his control panel
Plz help me!!!!
Thanking you in advance!
Posted: Thu Nov 09, 2006 1:33 am
by bob_the _builder
Using cookies ..
Something like should get u started:
Code: Select all
if (isset($_POST['rememberme'])) {
setcookie("username", $username, time()+60*60*24*100, "/");
setcookie("password", $password, time()+60*60*24*100, "/");
}
then check if a cookies is set:
Code: Select all
if (isset($_COOKIE['username'])) {
$username = $_COOKIE['username'];
}
if (isset($_COOKIE['password'])) {
$password = $_COOKIE['password'];
}
hth
Posted: Thu Nov 09, 2006 2:03 am
by dibyendrah
Another implemenation for same purpose but without encrypting cookies data .
Code: Select all
<?php
if (@$_POST["submit"] <> "") {
$bValidPwd = false ;
// Setup variables
$sUsername = @$_POST["username"];
$sPassword = @$_POST["password"];
if (ValidateUser($sUsername, $sPassword)) {
// Write cookies
$sLoginType = strtolower($_POST["rememberme"]);
$expirytime = time() + 365*24*60*60; // change cookie expiry time here
if ($sLoginType == "a") {
setCookie(CookieAutoLogin, "autologin", $expirytime);
setCookie(CookieUserName, $sUsername, $expirytime);
setCookie(CookiePassword, $sPassword, $expirytime);
} elseif ($sLoginType == "u") {
setCookie(CookieAutoLogin, "rememberusername", $expirytime);
setCookie(CookieUserName, $sUsername, $expirytime);
} else {
setCookie(CookieAutoLogin, "", $expirytime);
}
$_SESSION[SessionStatus] = "login";
ob_end_clean();
header("Location: index.php");
exit();
} else {
$_SESSION[SessionMessage] = "Incorrect user ID or password";
}
} else {
if (IsLoggedIn()) {
if ($_SESSION[SessionMessage] == "") {
ob_end_clean();
header("Location: index.php");
exit();
}
} else { // Check auto login
if (@$_COOKIE[CookieAutoLogin] == "autologin") {
$sUsername = @$_COOKIE[CookieUserName] ;
$sPassword = @$_COOKIE[CookiePassword] ;
}
if (ValidateUser($sUsername, $sPassword)) {
ob_end_clean();
header("Location: index.php");
exit();
}
}
}
?>
Cheers,
Dibyendra
Posted: Thu Nov 09, 2006 6:49 am
by feyd
Multiple cookies feels like overkill. You could generate a completely unrelated or likely very unique hash that uses only a single cookie. This hash could be built from a composite or username, password, the time and some other details and stored in the user record. Myself, I would also update this value every time the user logs in (automatic or not) to help remove the possibility that they are hijacked. This does affect the user experience however as it locks the auto-login ability to a single computer (and browser.)
Posted: Mon Nov 13, 2006 11:53 pm
by dibyendrah
how about password encryption and decryption of password using cookie ? a code sample please ...
Posted: Wed Dec 12, 2007 1:33 am
by parka
bob_the _builder wrote:Using cookies ..
Something like should get u started:
Code: Select all
if (isset($_POST['rememberme'])) {
setcookie("username", $username, time()+60*60*24*100, "/");
setcookie("password", $password, time()+60*60*24*100, "/");
}
then check if a cookies is set:
Code: Select all
if (isset($_COOKIE['username'])) {
$username = $_COOKIE['username'];
}
if (isset($_COOKIE['password'])) {
$password = $_COOKIE['password'];
}
hth
I suppose the username and password here will be used for a database connection to verify the legitimate user?
Posted: Wed Dec 12, 2007 5:11 pm
by feyd
This thread is over a year old, let it die.