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!
how to activate remember me checkbox
Moderator: General Moderators
-
bob_the _builder
- Forum Contributor
- Posts: 131
- Joined: Sat Aug 28, 2004 12:25 am
Using cookies ..
Something like should get u started:
then check if a cookies is set:
hth
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, "/");
}Code: Select all
if (isset($_COOKIE['username'])) {
$username = $_COOKIE['username'];
}
if (isset($_COOKIE['password'])) {
$password = $_COOKIE['password'];
}hth
- dibyendrah
- Forum Contributor
- Posts: 491
- Joined: Wed Oct 19, 2005 5:14 am
- Location: Nepal
- Contact:
Another implemenation for same purpose but without encrypting cookies data .
Cheers,
Dibyendra
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();
}
}
}
?>Dibyendra
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
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.)
- dibyendrah
- Forum Contributor
- Posts: 491
- Joined: Wed Oct 19, 2005 5:14 am
- Location: Nepal
- Contact:
I suppose the username and password here will be used for a database connection to verify the legitimate user?bob_the _builder wrote:Using cookies ..
Something like should get u started:
then check if a cookies is set:Code: Select all
if (isset($_POST['rememberme'])) { setcookie("username", $username, time()+60*60*24*100, "/"); setcookie("password", $password, time()+60*60*24*100, "/"); }
Code: Select all
if (isset($_COOKIE['username'])) { $username = $_COOKIE['username']; } if (isset($_COOKIE['password'])) { $password = $_COOKIE['password']; }
hth