YurunPHP中提供了丰富的Session操作和配置,无需手动session_start。
## 相关配置项
#### SESSION_NAME
用在 cookie 或者 URL 中的会话名称, 例如:PHPSESSID。 只能使用字母和数字作为会话名称,建议尽可能的短一些, 并且是望文知意的名字(对于启用了 cookie 警告的用户来说,方便其判断是否要允许此 cookie)。 如果指定了 name 参数, 那么当前会话也会使用指定值作为名称。
> 会话名称至少需要一个字母,不能全部都使用数字, 否则,每次都会生成一个新的会话 ID。
#### SESSION_SAVEPATH
指定Session文件存储目录,如果不指定按照PHP默认配置存储。
#### SESSION_USE_cookieS
sessionid在客户端采用的存储方式,置1代表使用cookie记录客户端的sessionid,同时,$_cookie变量里才会有$_cookie['PHPSESSIONID']这个元素存在
#### SESSION_CACHE_EXPIRE
Session的缓存有效期,单位为分钟
#### SESSION_CACHE_LIMITER
指定缓存机制名字
值 | 发送的Header |
|---|---|
public | Expires: (sometime in the future, according session.cache_expire) |
private_no_expire | Cache-Control: private, max-age=(session.cache_expire in the future), pre-check=(session.cache_expire in the future) |
private | Expires: Thu, 19 Nov 1981 08:52:00 GMT |
nocache | Expires: Thu, 19 Nov 1981 08:52:00 GMT |
#### SESSION_GC_PROBABILITY
每次请求时触发Session失效缓存清理的概率。取值范围:0.0-1.0
#### SESSION_MAX_LIFETIME
Session数据在服务器端储存的时间,如果超过这个时间,那么Session数据就自动删除!
#### SESSION_PREFIX
SESSION前缀
## 方法
#### 设置Session
Session::set($name, $value)
| 参数名 | 描述 |
| -- | -- |
| $name | session名称 |
| $value | session值 |
Session::set('pwd','123456'); // $_SESSION['pwd'] = '123456';
Session::set('@.pwd','123456'); // $_SESSION['prefix']['pwd'] = '123456';
#### 获取Session
Session::get($name = null, $default = false)
| 参数名 | 描述 |
| -- | -- |
| $name | session名称 |
| $default | 默认值 |
Session::get('pwd','123456'); // 取$_SESSION['pwd'],如果不存在返回123456
Session::get('@.pwd'); // 取$_SESSION['prefix']['pwd']的值
#### 删除Session
Session::delete($name = null)
| 参数名 | 描述 |
| -- | -- |
| $name | session名称 |
Session::delete('pwd'); // 删除$_SESSION['pwd']
Session::delete('@.pwd'); // 删除$_SESSION['prefix']['pwd']的值
#### 清空Session
Session::clear()
#### Session值是否存在
Session::exists($name)
| 参数名 | 描述 |
| -- | -- |
| $name | session名称 |
Session::exists('pwd'); // $_SESSION['pwd']是否存在
Session::exists('@.pwd'); // $_SESSION['prefix']['pwd']是否存在



