Skip to main content

"Remember Me" or "Keep Me login" like Facebook

You can make a Remember Me check box using simple cookie function.


Create a Cookie to store your Username and Password, this can be done as below :


Check the username & password and validate user if it is valid set a cookie for him and pass him inside site.

$check = $_POST['setcookie']; // Checks if the remember me check box was ticked , if not checked variable is null. 


if($check) 
  {
// Check to see if the 'setcookie' box was ticked to remember the user
setcookie("cookemail", $email, $time + 5000); // Sets the cookie username
setcookie("cookpassword", $password, $time + 5000); // Sets the cookie password
   }


 Now let him go inside.




Use below code on your page where your log in panel exist.:



***New Code for cookie***


if(isset($_COOKIE['cookemail']))
// If the cookie 'cook' is set, do the following;
{
$email = $_COOKIE['cookemail'];
//echo "Email :".$email;
// Select the username from the cookie
$password = $_COOKIE['cookpassword'];
//echo "Password :".$password;
// Select the password from the cookie
$query = "SELECT email,password FROM tnt_members WHERE email = '$username' AND password = '$password'";
$result = mysql_query($query);
if(mysql_num_rows($result))
// If the login information is correct do the following;
{
$_SESSION['loggedin'] = 1;
// Set the session 'loggedin' to 1 and forward the user to the admin page
header('Location:productg.php');
exit();
}
}
***New Code for cookie***




Comments

Popular posts from this blog