快速使用redis保存session信息

jopen 5年前

/**   * 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}");

来自: http://my.oschina.net/u/2269208/blog/598494