快速使用redis保存session信息
/** * redis配置 */ $config['redis_host'] = '127.0.0.1'; $config['redis_port'] = '6379'; /** * session配置 */ $config['sess_driver'] = 'redis'; $config['sess_save_path'] = "tcp://{$config['redis_host']}:{$config['redis_port']}"; $config['sess_cookie_name'] = 'ci_session'; $config['sess_expiration'] = 86400*365; /** * cookie配置 */ $cookie['cookie_prefix'] = ''; $cookie['cookie_domain'] = ''; $cookie['cookie_path'] = '/'; $cookie['cookie_secure'] = FALSE; $cookie['cookie_lifetime'] = $config['sess_expiration']; // ------------------------------------- 配置 end ----------------------------------- // 设置cookie session_set_cookie_params( $cookie['cookie_lifetime'], $cookie['cookie_path'], $cookie['cookie_domain'], $cookie['cookie_secure'], TRUE // HttpOnly; Yes, this is intentional and not configurable for security reasons ); /** * 设置session */ ini_set("session.save_handler", $config['sess_driver']); ini_set("session.save_path", $config['sess_save_path']); ini_set('session.name', $config['sess_cookie_name']); ini_set('session.gc_maxlifetime', $config['sess_expiration']); /** * 其他设置 */ // Security is king ini_set('session.use_trans_sid', 0); ini_set('session.use_strict_mode', 1); ini_set('session.use_cookies', 1); ini_set('session.use_only_cookies', 1); ini_set('session.hash_function', 1); ini_set('session.hash_bits_per_character', 4); session_start(); // 检查用户是否微触点登录 $redis = new redis(); $redis->connect($config['redis_host'], $config['redis_port']); $session_id = session_id(); $sess_str = $redis->get("ci_session:{$session_id}");
本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
转载本站原创文章,请注明出处,并保留原始链接、图片水印。
本站是一个以用户分享为主的开源技术平台,欢迎各类分享!