Ubiquity
2.5.2
php rapid development framework
Loading...
Searching...
No Matches
PhpSession.php
Go to the documentation of this file.
1
<?php
2
3
namespace
Ubiquity\utils\http\session
;
4
14
class
PhpSession
extends
AbstractSession
{
15
16
public
function
set
(
string
$key, $value) {
17
return
$_SESSION [$key] = $value;
18
}
19
20
public
function
get
(
string
$key, $default =
null
) {
21
return
$_SESSION [$key] ?? $default;
22
}
23
24
public
function
start
(
string
$name
=
null
) {
25
if
(! $this->
isStarted
()) {
26
if
(isset (
$name
) &&
$name
!==
''
) {
27
$this->name =
$name
;
28
}
29
if
(isset ( $this->name )) {
30
\session_name ( $this->name );
31
}
32
\session_start ();
33
$this->verifyCsrf->start ();
34
}
35
}
36
37
public
function
terminate
(): void {
38
if (! $this->
isStarted
()) {
39
return
;
40
}
41
$this->verifyCsrf->clear ();
42
$_SESSION = [];
43
44
if
(\ini_get (
'session.use_cookies'
)) {
45
$params = \session_get_cookie_params ();
46
\setcookie ( \session_name (),
''
, \time () - 42000, $params [
'path'
], $params [
'domain'
], $params [
'secure'
], $params [
'httponly'
] );
47
}
48
\session_destroy ();
49
}
50
51
public
function
isStarted
(): bool {
52
return \session_status () == PHP_SESSION_ACTIVE;
53
}
54
55
public
function
exists
(
string
$key): bool {
56
return isset ( $_SESSION [$key] );
57
}
58
59
public
function
getAll
(): array {
60
return $_SESSION;
61
}
62
63
public
function
delete
(
string
$key) {
64
unset ( $_SESSION [$key] );
65
}
66
67
public
function
regenerateId
(
bool
$deleteOldSession=
false
):bool {
68
return \session_regenerate_id($deleteOldSession);
69
}
70
71
public
function
visitorCount
(): int {
72
$sessionPath = \ini_get (
'session.save_path'
);
73
$sessionLifetime = \ini_get (
'session.gc_maxlifetime'
);
74
$files = glob ( $sessionPath . DS .
'sess_*'
);
75
$now = time ();
76
$count = 0;
77
foreach
( $files as $file ) {
78
if
(is_file ( $file )) {
79
if
($now - filemtime ( $file ) <= $sessionLifetime) {
80
$count ++;
81
}
82
}
83
}
84
return
$count;
85
}
86
}
87
Ubiquity\utils\http\session\AbstractSession
Ubiquity\utils\http\session$AbstractSession This class is part of Ubiquity.
Definition
AbstractSession.php:16
Ubiquity\utils\http\session\AbstractSession\$name
string $name
Definition
AbstractSession.php:17
Ubiquity\utils\http\session\PhpSession
Default php session.
Definition
PhpSession.php:14
Ubiquity\utils\http\session\PhpSession\start
start(string $name=null)
Definition
PhpSession.php:24
Ubiquity\utils\http\session\PhpSession\visitorCount
visitorCount()
Definition
PhpSession.php:71
Ubiquity\utils\http\session\PhpSession\isStarted
isStarted()
Definition
PhpSession.php:51
Ubiquity\utils\http\session\PhpSession\exists
exists(string $key)
Definition
PhpSession.php:55
Ubiquity\utils\http\session\PhpSession\regenerateId
regenerateId(bool $deleteOldSession=false)
Re-generates the session id.
Definition
PhpSession.php:67
Ubiquity\utils\http\session\PhpSession\terminate
terminate()
Definition
PhpSession.php:37
Ubiquity\utils\http\session\PhpSession\getAll
getAll()
Definition
PhpSession.php:59
Ubiquity\utils\http\session
Definition
AbstractSession.php:3
C:
Users
myadd
Documents
GitHub
ubiquity-doc-api
vendor
phpmv
ubiquity
src
Ubiquity
utils
http
session
PhpSession.php
Generated on Sun Dec 10 2023 15:04:27 for
Ubiquity
by
doxygen
1.9.8