forked from php-danfu.shenzhenbenwo.com

lefengyang
2025-09-10 3c9dcaf742cfa3e3c2b0843c8752cf7713aaf1fc
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
 
use Symfony\Component\HttpFoundation\Session\Storage\Handler\AbstractSessionHandler;
 
$parent = __DIR__;
while (!@file_exists($parent.'/vendor/autoload.php')) {
    if (!@file_exists($parent)) {
        // open_basedir restriction in effect
        break;
    }
    if ($parent === dirname($parent)) {
        echo "vendor/autoload.php not found\n";
        exit(1);
    }
 
    $parent = dirname($parent);
}
 
require $parent.'/vendor/autoload.php';
 
error_reporting(-1);
ini_set('html_errors', 0);
ini_set('display_errors', 1);
ini_set('session.gc_probability', 0);
ini_set('session.serialize_handler', 'php');
ini_set('session.cookie_lifetime', 0);
ini_set('session.cookie_domain', '');
ini_set('session.cookie_secure', '');
ini_set('session.cookie_httponly', '');
ini_set('session.use_cookies', 1);
ini_set('session.use_only_cookies', 1);
ini_set('session.cache_expire', 180);
ini_set('session.cookie_path', '/');
ini_set('session.cookie_domain', '');
ini_set('session.cookie_secure', 1);
ini_set('session.cookie_httponly', 1);
ini_set('session.use_strict_mode', 1);
ini_set('session.lazy_write', 1);
ini_set('session.name', 'sid');
ini_set('session.save_path', __DIR__);
ini_set('session.cache_limiter', '');
 
header_remove('X-Powered-By');
header('Content-Type: text/plain; charset=utf-8');
 
register_shutdown_function(function () {
    echo "\n";
    session_write_close();
    print_r(headers_list());
    echo "shutdown\n";
});
ob_start();
 
class TestSessionHandler extends AbstractSessionHandler
{
    private $data;
 
    public function __construct($data = '')
    {
        $this->data = $data;
    }
 
    public function open($path, $name)
    {
        echo __FUNCTION__, "\n";
 
        return parent::open($path, $name);
    }
 
    public function validateId($sessionId)
    {
        echo __FUNCTION__, "\n";
 
        return parent::validateId($sessionId);
    }
 
    /**
     * {@inheritdoc}
     */
    public function read($sessionId)
    {
        echo __FUNCTION__, "\n";
 
        return parent::read($sessionId);
    }
 
    /**
     * {@inheritdoc}
     */
    public function updateTimestamp($sessionId, $data)
    {
        echo __FUNCTION__, "\n";
 
        return true;
    }
 
    /**
     * {@inheritdoc}
     */
    public function write($sessionId, $data)
    {
        echo __FUNCTION__, "\n";
 
        return parent::write($sessionId, $data);
    }
 
    /**
     * {@inheritdoc}
     */
    public function destroy($sessionId)
    {
        echo __FUNCTION__, "\n";
 
        return parent::destroy($sessionId);
    }
 
    public function close()
    {
        echo __FUNCTION__, "\n";
 
        return true;
    }
 
    public function gc($maxLifetime)
    {
        echo __FUNCTION__, "\n";
 
        return true;
    }
 
    protected function doRead($sessionId)
    {
        echo __FUNCTION__.': ', $this->data, "\n";
 
        return $this->data;
    }
 
    protected function doWrite($sessionId, $data)
    {
        echo __FUNCTION__.': ', $data, "\n";
 
        return true;
    }
 
    protected function doDestroy($sessionId)
    {
        echo __FUNCTION__, "\n";
 
        return true;
    }
}