For more information, see setcookie (cookie_name, & nbsp; abcd, & nbsp; time () + 24*3600, A user can log on directly on to the same computer within 24 hours without having to log on to it. However, I think if the user closes the browser and re-opens the browser, he wants to have a login count, I don't know how to implement it. of course, if he closes the browser 24 hours a day and asks for the cookie count
Setcookie ("cookie_name", "abcd", time () + 24*3600 );
If such a cookie is set, users can log on directly on to the same computer 24 hours a day without having to log on. However, if the user closes the browser, re-open the browser and want him to have a login count. I don't know how to implement it. of course, if he closes the browser 100 times and then opens the browser 24 hours a day, it will count as 100 logins, we know that if you log on to the system, you can directly update the system once, but the sub-users do not log on. can you solve this problem through cookies or other methods? thank you.
------ Solution --------------------
You can check the cookie value. if the cookie value exists, the value is + 1.
------ Solution --------------------
Can be implemented with session
First, judge whether the session exists. otherwise, read the cookie and assign the cookie to the session.
Every time a cookie is assigned to a session, it is equivalent to a user login, cookie + 1;
The judgment code is as follows:
Ob_start ();
Session_start ();
$ Login_maxtime = 5; // The maximum number of logons with cookies
$ Session_login = isset ($ _ SESSION ['is _ login'])? 1: 0; // Get the session
If (! $ Session_login) {// The session does not exist
$ Is_login = isset ($ _ COOKIE ['is _ login'])? $ _ COOKIE ['is _ login']: 0; // Obtain the cookie
If ($ is_login & $ is_login <$ login_maxtime) {// The cookie exists and the number of session times assigned to the cookie is less than the set value
Setcookie ('is _ login', $ is_login + 1, time () + 24*3600 );
$ _ SESSION ['is _ login'] = 1;
Echo 'cur login time: '. $ is_login .'
';
} Else {// No cookie or more times
Setcookie ('is _ login ');
$ Is_login = 0;
}
} Else {// session exists
$ Is_login = 1;
}
If ($ is_login = 0 ){
Echo 'go to login ';
} Else {
Echo 'logined ';
}
?>
Simulate login, write session, cookies
ob_start();
session_start();
$_SESSION['is_login'] = 1;
setcookie('is_login', 1, time()+24*3600);
echo 'login success';
?>