C0py this to moduls/func.php


if (isset($_COOKIE["username"]) && isset($_COOKIE["password"]) && !isset($_SESSION["user"]))
{
$cuser = $_COOKIE["username"];
$cpass = $_COOKIE["password"];
$check = mysql_num_rows(mysql_query("SELECT `username` FROM `b_users` WHERE `username` = '$cuser' AND `password` = '$cpass'"));
if ($check > 0)
{
$_SESSION["user"] = $cuser;
} else {
setcookie("username", "", time()-86400);
setcookie("password", "", time()-86400);
}

}


put it after <?php

after that


Then open /loguser.php, look for $_SESSION["user"]=$username;. under it, paste this code.

$CookieExpire = 200; //The number of days after which the cookie would expire.
$time = 60 * 60 * 24 * $CookieExpire;
$time = time() + $time;
setcookie("username", "$username", "$time");
setcookie("password", "$password", "$time");

change $CookieExpire to the number of your days the cookie would be deleted from the users
browser. And Save!


Then open /logout.php immediately after unset($_SESSION["user"]), paste this..
<?php
setcookie("username", "", time()-86400);
setcookie("password", "", time()-86400);
?>

Loading...
  • Date: Jan 04, 2014

Well users of this code should note that. This code would be 95% effective if the user has cookies enabled on the browser.

So @nonirap u could as well add a cookie detection script which detects if a users browser cookie is on. Otherwise it alerts the visitor.

  • Date: Jan 04, 2014

Also as an addon, you SHOULDN'T store passwords in COOKIE as it can be manipulated or stolen.

You can consider storing a unique id which you check against IP you stored in your db when the visitor returns.

  • Date: Sep 09, 2016
Also as an addon, you SHOULDN'T store passwords in COOKIE as it can be manipulated or stolen.

You can consider storing a unique id which you check against IP you stored in your db when the visitor returns.
Gerardcole

Please How Can I Do That Sir