持久化登录解决方案
方案一:
将user_id,user_password,加密后存入cookie中,设置有效时长
if (!empty($_COOKIE['ECS']['user_id']) && !empty($_COOKIE['ECS']['password'])) { $condition = array('user_id' => intval($_COOKIE['ECS']['user_id']), 'password' => $_COOKIE['ECS']['password']); $row = $this->db->table('users')->where($condition)->find(); if (!$row) { $time = time() - 3600; cookie('ECS[user_id]', ''); cookie('ECS[password]', ''); } else { $_SESSION['user_id'] = $row['user_id']; $_SESSION['user_name'] = $row['user_name']; update_user_info(); } }
方案二:
设置session_id的有效时长
session.use_cookies = 1 session.use_only_cookies = 1 session.cookie_lifetime = 604800 session.gc_maxlifetime = 604800