Skip to content

Commit a443831

Browse files
committed
对Session库添加驱动配置文件
1 parent edd7378 commit a443831

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

lib/session.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,16 @@ class Session implements SessionInterface
2525

2626
/**
2727
* @param string $drive_name
28+
* @param array $drive_cfg 驱动配置
2829
* @throws \Exception
2930
*/
30-
function __construct($drive_name = 'Local') {
31+
function __construct($drive_name = 'Local',$drive_cfg=[]) {
3132
c_lib()->load('session/' . $drive_name);
3233
$drive_name = "CLib\\Session\\" . $drive_name;
3334
if(!class_exists($drive_name)){
3435
throw new \Exception(_("Session Drive Not Found"));
3536
}
36-
$this->drive = new $drive_name();
37+
$this->drive = new $drive_name($drive_cfg);
3738
}
3839

3940
public function get($name) {

lib/session/Local.php

+15-2
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,22 @@ class Local implements SessionInterface
2222

2323
/**
2424
* 启动Session
25+
* @param array $cfg
2526
*/
26-
function __construct() {
27-
session_start();
27+
public function __construct($cfg=[]) {
28+
$config = [
29+
'lifetime' => 0,
30+
'path' => NULL,
31+
'domain' => NULL,
32+
'secure' => false,
33+
'httponly' => true
34+
];
35+
$config = array_merge($config, $cfg);
36+
session_set_cookie_params($config['lifetime'], $config['path'], $config['domain'], $config['secure'], $config['httponly']);
37+
if(session_status() != PHP_SESSION_ACTIVE){
38+
//Session未启用
39+
session_start();
40+
}
2841
}
2942

3043
/**

0 commit comments

Comments
 (0)