. How Do You Keep PHP Session Active As per the Coockies.
Bloggers Choice[Sep-23-2019]    

How Do You Keep PHP Session Active As per the Coockies.


Before we talk about the active session and session time out, firstly we should be aware of what are PHP Cookies and how it will work for various purposes.

A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's computer. Each time the same computer requests a page with a browser, it will send the cookie too. With PHP, you can both create and retrieve cookie values.

Syntax
setcookie(name, value, expire, path, domain, secure, httponly);

Example:

$cookie_name = "user";
$cookie_value = "John Doe";
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/"); // 86400 = 1 day
?>



if(!isset($_COOKIE[$cookie_name])) {
echo "Cookie named '" . $cookie_name . "' is not set!";
} else {
echo "Cookie '" . $cookie_name . "' is set!
";
echo "Value is: " . $_COOKIE[$cookie_name];
}
?>



Source:https://stackoverflow.com/questions/28743481/how-can-i-keep-my-users-logged-in-forever
How can i keep my users logged in “forever”?
setcookie("login_info", $login_info, time()+3600*24*30*12*10)

Comments - 1


Coding Tips 4 years ago

Accepted that it's very important topic to be discussed. Really looking forward to read this..