Files
shopxo/config/cookie.php

59 lines
2.2 KiB
PHP
Raw Permalink Normal View History

2018-12-28 18:58:37 +08:00
<?php
// +----------------------------------------------------------------------
// | ShopXO 国内领先企业级B2C免费开源电商系统
// +----------------------------------------------------------------------
2021-03-16 10:34:52 +08:00
// | Copyright (c) 2011~2099 http://shopxo.net All rights reserved.
2018-12-28 18:58:37 +08:00
// +----------------------------------------------------------------------
2021-03-16 10:34:52 +08:00
// | Licensed ( https://opensource.org/licenses/mit-license.php )
2018-12-28 18:58:37 +08:00
// +----------------------------------------------------------------------
// | Author: Devil
// +----------------------------------------------------------------------
// +----------------------------------------------------------------------
2026-06-02 16:15:31 +08:00
// | Cookie设置部分项读取后台 系统配置 → Cookie配置
2018-12-28 18:58:37 +08:00
// +----------------------------------------------------------------------
2024-11-05 16:03:39 +08:00
$cookie_domain = MyFileConfig('common_cookie_domain', '', '', true);
2025-03-03 17:49:22 +08:00
if(!empty($cookie_domain))
2024-10-21 10:51:14 +08:00
{
2025-03-03 17:49:22 +08:00
if(substr($cookie_domain, 0, 1) != '.')
{
$cookie_domain = '.'.$cookie_domain;
}
} else {
$cookie_domain = __MY_MAIN_DOMAIN__;
2024-10-21 10:51:14 +08:00
}
2026-06-02 16:15:31 +08:00
$cookie_secure = ((int) MyFileConfig('common_cookie_secure', '', 0, true) == 1);
$cookie_httponly = ((int) MyFileConfig('common_cookie_httponly', '', 0, true) == 1);
$cookie_samesite_raw = MyFileConfig('common_cookie_samesite', '', '', true);
$cookie_samesite_raw = is_string($cookie_samesite_raw) ? strtolower(trim($cookie_samesite_raw)) : '';
$cookie_samesite = '';
if($cookie_samesite_raw == 'strict')
{
$cookie_samesite = 'strict';
} elseif($cookie_samesite_raw == 'lax')
{
$cookie_samesite = 'lax';
}
$cookie_expire_cfg = MyFileConfig('common_cookie_expire', '', '', true);
$cookie_expire = empty($cookie_expire_cfg) ? 0 : (int) $cookie_expire_cfg;
2018-12-28 18:58:37 +08:00
return [
2026-06-02 16:15:31 +08:00
// cookie 保存时间(秒)
'expire' => $cookie_expire,
2018-12-28 18:58:37 +08:00
// cookie 保存路径
'path' => '/',
// cookie 有效域名
2024-10-21 10:51:14 +08:00
'domain' => $cookie_domain,
2018-12-28 18:58:37 +08:00
// cookie 启用安全传输
2026-06-02 16:15:31 +08:00
'secure' => $cookie_secure,
2018-12-28 18:58:37 +08:00
// httponly设置
2026-06-02 16:15:31 +08:00
'httponly' => $cookie_httponly,
2018-12-28 18:58:37 +08:00
// 是否使用 setcookie
'setcookie' => true,
2026-06-02 16:15:31 +08:00
// samesite 设置(与文件配置一致用小写 strict / lax空表示由浏览器默认
'samesite' => $cookie_samesite,
2018-12-28 18:58:37 +08:00
];
2018-12-29 13:13:09 +08:00
?>