-
Notifications
You must be signed in to change notification settings - Fork 0
/
SessionConfiguration.php
executable file
·73 lines (63 loc) · 2.06 KB
/
SessionConfiguration.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
<?php
/*
* This file is part of the Koded package.
*
* (c) Mihail Binev <[email protected]>
*
* Please view the LICENSE distributed with this source code
* for the full copyright and license information.
*
*/
namespace Koded\Session;
use Koded\Stdlib\{Config, Immutable};
use Koded\Stdlib\Interfaces\ConfigurationFactory;
class SessionConfiguration extends Config
{
public function __construct(ConfigurationFactory $settings)
{
$this
->set('name', 'session')
->import($settings->get('session', []))
->import([
'use_strict_mode' => '1', // enable to prevent session fixation
'use_trans_sid' => '0', // disable to prevent session fixation and hijacking
'use_only_cookies' => '1', // disable session identifiers in the URLs
'cache_limiter' => '', // disable response headers
'referer_check' => '', // disable it, not a safe implementation (with substr() check)
]);
if ($this->get('expire_at_browser_close')) {
ini_set('session.cookie_lifetime', 0);
$this->set('cookie_lifetime', 0);
}
foreach ($this as $name => $value) {
@ini_set('session.' . $name, $value);
}
}
public function handler(): string
{
return $this->get('save_handler', 'files');
}
/**
* Session directives for session_start() function.
*
* @return array
*/
public function sessionParameters(): array
{
return (new Immutable($this->filter(ini_get_all('session', false), 'session.', false)))
->extract([
'cache_expire',
'cache_limiter',
'gc_maxlifetime',
'name',
'referer_check',
'serialize_handler',
'sid_bits_per_character',
'sid_length',
'use_cookies',
'use_only_cookies',
'use_strict_mode',
'use_trans_sid',
]);
}
}