PHP

REMEMBER LOGIC IN LOGIN

On Login:

if(isset($_POST['remember'])) {
$month = time() + ( ( 3600 * 24 ) * 30 );
setcookie('remember_me', $user_id, $month);
}
else {
$past = time() - 100;
setcookie('remember_me', '', $past);
}

On Logout:

$past = time() - 100;
setcookie('remember_me', '', $past);

Exact after connection.php file in project:

if( isset($_COOKIE['remember_me']) AND trim($_COOKIE['remember_me'] ) != "" ) {
//Store the sessions which you set at the time of login.
$_SESSION["authenticated"] = 'true';
$_SESSION["user_id"] = $_COOKIE['remember_me'];
}

Leave a Reply

Your email address will not be published. Required fields are marked *