Thinkphp3.2, by default, the system will automatically start the session after initialization, and the implementation of automatic login within two weeks
Because the session has been automatically started, the session initialization setting has not been implemented; resulting in ini_set(session.gc_maxlifetime, $name[‘expire’]);ini_set(session.cookie_lifetime, $name[‘expire’]), and none of them can be set, so the session can basically be determined to be temporarily unresolved;
It has to start from the cookie aspect, although there are certain security problems, so it is necessary to carry out the encryption processing of cookies, about the realization of automatic login;
//If automatic login is checked, set the cookie[‘autologin’]
if(i(post.autologin) == 1) {
//$expire = 1209600; //Save for two weeks
$autologin = serialize(array(UID=> $uid,LAST_LOGIN_TIME=> time(),LAST_LOGIN_IP => get_client_ip(1));
cookie(autologin, think_encrypt($autologin), 1209600);
}
think_encrypt is an encryption function, when the application has already exited, and the cookie[‘autologin’]When it exists, you need to:
/* Login automatically within two weeks */
if(!is_login() && cookie(autologin)) {
$autologin = unserialize(think_decrypt(cookie(autologin)));
if (is_array($autologin) && $autologin[‘last_login_ip’]== get_client_ip(1)) {
/* login user */
$member = d(member);
$member->login($autologin[‘uid’]);
}
}
Among them, think_encrypt and think_decrypt are added and decrypted functions respectively;
The basic logic is roughly as above;

![如果勾选自动登录,则设置COOKIE['autologin']](https://www.shuijingwanwq.com/wp-content/uploads/2015/05/10.png)