File: Builtin.php

package info (click to toggle)
php-horde-sessionhandler 2.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 396 kB
  • sloc: php: 1,487; xml: 672; sh: 14; makefile: 2
file content (115 lines) | stat: -rw-r--r-- 2,613 bytes parent folder | download
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
<?php
/**
 * SessionHandler storage implementation for PHP's built-in session handler.
 * This doesn't do any session handling itself - instead, it exists to allow
 * utility features to be used with the built-in PHP handler.
 *
 * Copyright 2005-2017 Horde LLC (http://www.horde.org/)
 *
 * See the enclosed file COPYING for license information (LGPL). If you
 * did not receive this file, see http://www.horde.org/licenses/lgpl21.
 *
 * @author   Matt Selsky <selsky@columbia.edu>
 * @category Horde
 * @license  http://www.horde.org/licenses/lgpl21 LGPL 2.1
 * @package  SessionHandler
 */
class Horde_SessionHandler_Storage_Builtin extends Horde_SessionHandler_Storage
{
    /**
     * Directory with session files.
     *
     * @var string
     */
    protected $_path;

    /**
     */
    public function __construct(array $params = array())
    {
        parent::__construct($params);

        $this->_path = session_save_path();
        if (!$this->_path) {
            $this->_path = sys_get_temp_dir();
        }
    }

    /**
     */
    public function open($save_path = null, $session_name = null)
    {
    }

     /**
      */
    public function close()
    {
    }

    /**
     */
    public function read($id)
    {
        return strval(@file_get_contents($this->_path . '/sess_' . $id));
    }

    /**
     */
    public function write($id, $session_data)
    {
        return false;
    }

    /**
     */
    public function destroy($id)
    {
        try {
            $di = new DirectoryIterator($this->_path);
        } catch (UnexpectedValueException $e) {
            return false;
        }

        foreach ($di as $val) {
            /* Make sure we're dealing with files that start with sess_. */
            if ($val->isFile() &&
                ($val->getFilename() == 'sess_' . $id)) {
                return unlink($val->getPathname());
            }
        }

        return false;
    }

    /**
     */
    public function gc($maxlifetime = 300)
    {
        return false;
    }

    /**
     */
    public function getSessionIDs()
    {
        $sessions = array();

        try {
            $di = new DirectoryIterator($this->_path);
        } catch (UnexpectedValueException $e) {
            return $sessions;
        }

        foreach ($di as $val) {
            /* Make sure we're dealing with files that start with sess_. */
            if ($val->isFile() &&
                (strpos($val->getFilename(), 'sess_') === 0)) {
                $sessions[] = substr($val->getFilename(), strlen('sess_'));
            }
        }

        return $sessions;
    }

}