-
Notifications
You must be signed in to change notification settings - Fork 0
/
cookie.php
67 lines (63 loc) · 1.41 KB
/
cookie.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
<?php
namespace ScpoPHP;
require_once 'config.php';
use ScpoPHP\Config\Cookie as Cfg;
/**
* cookie简便函数
* @link http://scpo-php.seventop.top/cookie/
*/
class Cookie
{
/**
* 发送一个cookie
* @param string $name 名称
* @param string $value 值
* @param string $path 作用路径
* @param string $domain 作用域名
* @param bool $secure 仅限安全连接
* @param bool $httponly 仅限http连接
* @param bool 是否成功发送
*/
static public function set(
$name,
$value = Cfg\NO_PARAM_SIGN,
$expires_or_options = Cfg\NO_PARAM_SIGN,
$path = Cfg\NO_PARAM_SIGN,
$domain = Cfg\NO_PARAM_SIGN,
$secure = Cfg\NO_PARAM_SIGN,
$httponly = Cfg\NO_PARAM_SIGN
) {
return setcookie(...self::getParams(
Cfg::$params,
$name,
$value,
$expires_or_options,
$path,
$domain,
$secure,
$httponly
));
}
static public function getParams(
$default,
$name,
$value = Cfg\NO_PARAM_SIGN,
$expires_or_options = Cfg\NO_PARAM_SIGN,
$path = Cfg\NO_PARAM_SIGN,
$domain = Cfg\NO_PARAM_SIGN,
$secure = Cfg\NO_PARAM_SIGN,
$httponly = Cfg\NO_PARAM_SIGN
) {
$xop = array(
'name' => $name,
'value' => $value,
'expires_or_options' => $expires_or_options,
'path' => $path,
'domain' => $domain,
'secure' => $secure,
'httponly' => $httponly
);
foreach ($xop as $param => $val) if ($val !== Cfg\NO_PARAM_SIGN) $default[$param] = $val;
return $default;
}
}