1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace XoopsModules\Xoopstube; |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
You may not change or alter any portion of this comment or credits |
7
|
|
|
of supporting developers from this source code or any supporting source code |
8
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
9
|
|
|
|
10
|
|
|
This program is distributed in the hope that it will be useful, |
11
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
12
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Session class |
17
|
|
|
* |
18
|
|
|
* @copyright The XUUPS Project http://sourceforge.net/projects/xuups/ |
19
|
|
|
* @license http://www.fsf.org/copyleft/gpl.html GNU public license |
20
|
|
|
* @package Xoopstube |
21
|
|
|
* @since 1.0 |
22
|
|
|
* @author trabis <[email protected]> |
23
|
|
|
* @author Harry Fuecks (PHP Anthology Volume II) |
24
|
|
|
*/ |
25
|
|
|
|
26
|
|
|
use XoopsModules\Xoopstube; |
27
|
|
|
|
28
|
|
|
require_once \dirname(__DIR__) . '/include/common.php'; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Class Session |
32
|
|
|
*/ |
33
|
|
|
class Session |
34
|
|
|
{ |
35
|
|
|
/** |
36
|
|
|
* Session constructor<br> |
37
|
|
|
* Starts the session with session_start() |
38
|
|
|
* <strong>Note:</strong> that if the session has already started, |
39
|
|
|
* session_start() does nothing |
40
|
|
|
*/ |
41
|
|
|
protected function __construct() |
42
|
|
|
{ |
43
|
|
|
if (false === @\session_start()) { |
44
|
|
|
throw new \RuntimeException('Session could not start.'); |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Sets a session variable |
50
|
|
|
* |
51
|
|
|
* @param string $name name of variable |
52
|
|
|
* @param mixed $value value of variable |
53
|
|
|
* |
54
|
|
|
* @access public |
55
|
|
|
*/ |
56
|
|
|
public function set($name, $value) |
57
|
|
|
{ |
58
|
|
|
$_SESSION[$name] = $value; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Fetches a session variable |
63
|
|
|
* |
64
|
|
|
* @param string $name name of variable |
65
|
|
|
* |
66
|
|
|
* @return mixed value of session variable |
67
|
|
|
* @access public |
68
|
|
|
*/ |
69
|
|
|
public function get($name) |
70
|
|
|
{ |
71
|
|
|
return $_SESSION[$name] ?? false; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Deletes a session variable |
76
|
|
|
* |
77
|
|
|
* @param string $name name of variable |
78
|
|
|
* |
79
|
|
|
* @access public |
80
|
|
|
*/ |
81
|
|
|
public function del($name) |
82
|
|
|
{ |
83
|
|
|
unset($_SESSION[$name]); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Destroys the whole session |
88
|
|
|
* |
89
|
|
|
* @access public |
90
|
|
|
*/ |
91
|
|
|
public function destroy() |
92
|
|
|
{ |
93
|
|
|
$_SESSION = []; |
94
|
|
|
\session_destroy(); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @return Session |
99
|
|
|
*/ |
100
|
|
|
public static function getInstance() |
101
|
|
|
{ |
102
|
|
|
static $instance; |
103
|
|
|
if (null === $instance) { |
104
|
|
|
$instance = new static(); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
return $instance; |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|