-
Notifications
You must be signed in to change notification settings - Fork 44
/
Session.php
85 lines (79 loc) · 1.61 KB
/
Session.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
/**
* YYF - A simple, secure, and efficient PHP RESTful Framework.
*
* @link https://github.com/YunYinORG/YYF/
*
* @license Apache2.0
* @copyright 2015-2017 NewFuture@yunyin.org
*/
/**
*Session seession管理
*
* @author NewFuture
*/
class Session
{
private static $_id;
/**
* @param string $id session_id
*
* @return string [session id]
*/
public static function start($id = null)
{
if (!$sid = self::$_id) {
if (($sid = $id) || Input::I('SERVER.HTTP_SESSION_ID', $sid, 'ctype_alnum')) {
session_id($sid);
session_start();
} else {
session_start();
$sid = session_id();
}
self::$_id = $sid;
}
return $sid;
}
/**
* 设置session
*
* @param string $name 键值
* @param mixed $value 对应值
*/
public static function set($name, $value)
{
self::start();
return $_SESSION[$name] = $value;
}
/**
* 读取
*
* @param string $name 键值
*/
public static function get($name)
{
self::start();
return isset($_SESSION[$name]) ? $_SESSION[$name] : null;
}
/**
* 删除
*
* @param string $name 键值
*/
public static function del($name)
{
self::start();
unset($_SESSION[$name]);
}
/**
* 清空session
*/
public static function flush()
{
self::start();
unset($_SESSION);
session_unset();
session_destroy();
self::$_id = null;
}
}