栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > PHP > php开源框架 > YurunPHP

Session - YurunPHP1.0开发手册

YurunPHP 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Session - YurunPHP1.0开发手册


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)
Cache-Control: public, max-age=(sometime in the future, according to session.cache_expire)
Last-Modified: (the timestamp of when the session was last saved)


private_no_expire

Cache-Control: private, max-age=(session.cache_expire in the future), pre-check=(session.cache_expire in the future)
Last-Modified: (the timestamp of when the session was last saved)


private

Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: private, max-age=(session.cache_expire in the future), pre-check=(session.cache_expire in the future)
Last-Modified: (the timestamp of when the session was last saved)


nocache

Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache


#### 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']是否存在


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/213866.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号