1<?php
2/**
3 * SessionHandler storage implementation for PHP's built-in session handler.
4 * This doesn't do any session handling itself - instead, it exists to allow
5 * utility features to be used with the built-in PHP handler.
6 *
7 * Copyright 2005-2017 Horde LLC (http://www.horde.org/)
8 *
9 * See the enclosed file COPYING for license information (LGPL). If you
10 * did not receive this file, see http://www.horde.org/licenses/lgpl21.
11 *
12 * @author   Matt Selsky <selsky@columbia.edu>
13 * @category Horde
14 * @license  http://www.horde.org/licenses/lgpl21 LGPL 2.1
15 * @package  SessionHandler
16 */
17class Horde_SessionHandler_Storage_Builtin extends Horde_SessionHandler_Storage
18{
19    /**
20     * Directory with session files.
21     *
22     * @var string
23     */
24    protected $_path;
25
26    /**
27     */
28    public function __construct(array $params = array())
29    {
30        parent::__construct($params);
31
32        $this->_path = session_save_path();
33        if (!$this->_path) {
34            $this->_path = sys_get_temp_dir();
35        }
36    }
37
38    /**
39     */
40    public function open($save_path = null, $session_name = null)
41    {
42    }
43
44     /**
45      */
46    public function close()
47    {
48    }
49
50    /**
51     */
52    public function read($id)
53    {
54        return strval(@file_get_contents($this->_path . '/sess_' . $id));
55    }
56
57    /**
58     */
59    public function write($id, $session_data)
60    {
61        return false;
62    }
63
64    /**
65     */
66    public function destroy($id)
67    {
68        return false;
69    }
70
71    /**
72     */
73    public function gc($maxlifetime = 300)
74    {
75        return false;
76    }
77
78    /**
79     */
80    public function getSessionIDs()
81    {
82        $sessions = array();
83
84        try {
85            $di = new DirectoryIterator($this->_path);
86        } catch (UnexpectedValueException $e) {
87            return $sessions;
88        }
89
90        foreach ($di as $val) {
91            /* Make sure we're dealing with files that start with sess_. */
92            if ($val->isFile() &&
93                (strpos($val->getFilename(), 'sess_') === 0)) {
94                $sessions[] = substr($val->getFilename(), strlen('sess_'));
95            }
96        }
97
98        return $sessions;
99    }
100
101}
102