I'm currently thinking an issues related to PHP cookies.
1) Here is my case. User can sign in and then view my page.
2) Then user stop at page3, user want to sign out and exit.
3) He can save his current page location(page3) in cookies, to make him can directly enter to page3 when he login in the future.
So, may I ask,if i use cookies on this, how should I store it in cookies? For the page location.
Can give me some idea on it?
-
php.net/manual/en/features.cookies.phpPrafulla Kumar Sahu– Prafulla Kumar Sahu2015年11月28日 08:58:07 +00:00Commented Nov 28, 2015 at 8:58
2 Answers 2
If you are using PHP I believe you could also use $_SESSION to save his location and login info.
Comments
If you want user to be able to close broswer, open it again and still be signed in, use cookies (with specified expiration time). You can use session if you will be satisfied with fact that as long as user closes the browser he will be signed out.
SETTING THE COOKIE
<?php
$cookie_name = "user";
$cookie_value = "John Doe";
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/"); // 86400 = 1 day
?>
SESSION USAGE
session_start();
put a user id in the session to track who is logged in
$_SESSION['user'] = $user_id;
Check if someone is logged in
if (isset($_SESSION['user'])) {
// logged in
} else {
// not logged in
}
Find the logged in user ID
$_SESSION['user']
So on your page
<?php
session_start();
if (isset($_SESSION['user'])) {
?>
logged in HTML and code here
<?php
} else {
?>
Not logged in HTML and code here
<?php
}