config/session.php 配置文件

session.php 配置文件标注
  • session.php laravel5.4 源码
 session 存储位置
    //> 默认file:文件形式存储,存储位置在file参数里设置
    //> cookie :cookie形式保存
    //> database :数据库形式保存 参看 table、connection参数配置
    //> apc :php的一个扩展存储数据
    //> memcached:缓存存储推荐
    //> redis:缓存存储
    //> array :php数组形式存储 测试时使用
    'driver' => env('SESSION_DRIVER', 'file'),

    /*
    |--------------------------------------------------------------------------
    | Session Lifetime
    |--------------------------------------------------------------------------
    |
    | Here you may specify the number of minutes that you wish the session
    | to be allowed to remain idle before it expires. If you want them
    | to immediately expire on the browser closing, set that option.
    |
    */

    //> 用于cookie 设置 配合expire_on_close、cookie、path、domain、secure、http_only一起被使用
    //> 配合下面 expire_on_close 参数一起使用 (参数单位:分钟)
    //> driver=file时,lifetime被用于文件最后修改时间判断
    'lifetime' => 120,

    //> 用于cookie 设置 配合expire_on_close、cookie、path、domain、secure、http_only一起被使用
    //> expire_on_close 响应seesion_cookie是否设置过期
    //> false:开启过期时间设置 过期时间 lifetime 参数 分钟
    //> true : 关闭过期时间 永不过期 (相当于lifetime => 0)
    //> 在中间件 \Illuminate\Session\Middleware\StartSession::class 被使用
    'expire_on_close' => false,

    /*
    |--------------------------------------------------------------------------
    | Session Encryption
    |--------------------------------------------------------------------------
    |
    | This option allows you to easily specify that all of your session data
    | should be encrypted before it is stored. All encryption will be run
    | automatically by Laravel and you can use the Session like normal.
    |
    */

    //> 加密所有会话数据 推荐开启 true 这里的Laravel_cookie 就算设置为false 也会自动加密存储在浏览器上
    'encrypt' => false,

    /*
    |--------------------------------------------------------------------------
    | Session File Location
    |--------------------------------------------------------------------------
    |
    | When using the native session driver, we need a location where session
    | files may be stored. A default has been set for you but a different
    | location may be specified. This is only needed for file sessions.
    |
    */

    //> session 保存在本地时,存储文件位置(已文件形式存储时)
    'files' => storage_path('framework/sessions'),

    /*
    |--------------------------------------------------------------------------
    | Session Database Connection
    |--------------------------------------------------------------------------
    |
    | When using the "database" or "redis" session drivers, you may specify a
    | connection that should be used to manage these sessions. This should
    | correspond to a connection in your database configuration options.
    |
    */
    //> 参数在 driver 被设置为redis或database时有用
    //> 在使用redis或database(数据库)时,需要指定一个连接
    //> database:时指定 mysql 等 参看database.php 文件相关数据库链接配置
    //> redis:时指定 default 等 参看database.php 文件相关redis相关配置项
    'connection' => null,

    /*
    |--------------------------------------------------------------------------
    | Session Database Table
    |--------------------------------------------------------------------------
    |
    | When using the "database" session driver, you may specify the table we
    | should use to manage the sessions. Of course, a sensible default is
    | provided for you; however, you are free to change this as needed.
    |
    */

    //> session cookie 存在在database数据库中时,数据库表名称
    'table' => 'sessions',

    /*
    |--------------------------------------------------------------------------
    | Session Cache Store
    |--------------------------------------------------------------------------
    |
    | When using the "apc" or "memcached" session drivers, you may specify a
    | cache store that should be used for these sessions. This value must
    | correspond with one of the application's configured cache stores.
    |
    */
    //> session存储在apc或memcached缓存中指定
    'store' => null,

    /*
    |--------------------------------------------------------------------------
    | Session Sweeping Lottery
    |--------------------------------------------------------------------------
    |
    | Some session drivers must manually sweep their storage location to get
    | rid of old sessions from storage. Here are the chances that it will
    | happen on a given request. By default, the odds are 2 out of 100.
    |
    */

    //> 概率:当前触发一次清理session数据触发概率 当前表示100次中可能存在2次触发清理session过期数据
    //> 该参数触发机制,代码触发 并非php系统触发调用gc()方法
    'lottery' => [2, 100],

    /*
    |--------------------------------------------------------------------------
    | Session Cookie Name
    |--------------------------------------------------------------------------
    |
    | Here you may change the name of the cookie used to identify a session
    | instance by ID. The name specified here will get used every time a
    | new session cookie is created by the framework for every driver.
    |
    */

    //> session_cookie 会话名称 (需要时自行修改)
    //> 流浪器服务器一次会话名称。参看php.ini的配置项session.name
    //> php是默认的 session.name = PHPSESSID Laravel经过ini_set修改了值
    //> php中支持 ini_set()函数修改php.ini文件变量数据,也可以使用session_name()函数修改php.ini中session.name名称
    'cookie' => 'laravel_session',

    /*
    |--------------------------------------------------------------------------
    | Session Cookie Path
    |--------------------------------------------------------------------------
    |
    | The session cookie path determines the path for which the cookie will
    | be regarded as available. Typically, this will be the root path of
    | your application but you are free to change this when necessary.
    |
    */

    //> 会话cookie存放位置 "/" 表示存放在根域名下,通常建议这样做
    'path' => '/',

    /*
    |--------------------------------------------------------------------------
    | Session Cookie Domain
    |--------------------------------------------------------------------------
    |
    | Here you may change the domain of the cookie used to identify a session
    | in your application. This will determine which domains the cookie is
    | available to in your application. A sensible default has been set.
    |
    */

    //> 设置 session_cookie 子域,使当前会话在当前子域中使用
    //> 比如设置为 xxx.com 在 s.xxx.com 一样可用
    'domain' => env('SESSION_DOMAIN', null),

    /*
    |--------------------------------------------------------------------------
    | HTTPS Only Cookies
    |--------------------------------------------------------------------------
    |
    | By setting this option to true, session cookies will only be sent back
    | to the server if the browser has a HTTPS connection. This will keep
    | the cookie from being sent to you if it can not be done securely.
    |
    */

    //> secure : 可选值 true / false
    //> true :表示cookie在 https 传输下有效
    //> false : 表示在http或https下传递都有效
    //> 如果是http 设置 secure 为默认的false即可 
    'secure' => env('SESSION_SECURE_COOKIE', false),

    /*
    |--------------------------------------------------------------------------
    | HTTP Access Only
    |--------------------------------------------------------------------------
    |
    | Setting this value to true will prevent JavaScript from accessing the
    | value of the cookie and the cookie will only be accessible through
    | the HTTP protocol. You are free to modify this option if needed.
    |
    */
    
    //> 可选值 bool true / false
    //> true:当true时,cookie只能通过HTTP协议访问。
    //> 这意味着cookie不能通过脚本语言(如JavaScript)访问。它已经表明,这种设置可以有效地帮助通过XSS攻击减少身份盗窃(虽然不是所有的浏览器都支持) 
    //> false :默认值 (通常)
    'http_only' => true,

];
  • 如有错误请指正,谢谢!!!

你可能感兴趣的:(config/session.php 配置文件)