Repository navigation
Expand file tree
/
Copy pathSessionManager.php
More file actions
75 lines (73 loc) · 1.98 KB
/
Copy pathSessionManager.php
File metadata and controls
75 lines (73 loc) · 1.98 KB
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
<?php
date_default_timezone_set('Asia/Tehran');
class SessionManager
{
private $sess;
public function __construct($tbl)
{
$this->sess = $tbl;
}
public function AddSession(string $username ,string $type, string $ip): string
{
foreach($this->sess as $row => $value)
{
if($value['user'] == $username)
{
echo 'exist';
return $row;
}
}
$code = uniqid($username.$type, true);
echo 'added';
$this->sess->set($code, array('user' => $username, 'type' => $type, 'ts' => time(), 'ip' => $ip) );
return $code;
}
public function DelSession(string $code): void
{
$this->sess->del($code);
}
public function ValidateSession($code, $cip): bool
{
if($this->sess->exists($code))
{
$date = $this->sess->get($code, 'ts');
$ip = $this->sess->get($code, 'ts');
$diff = (time() - $date) / 60;
if($diff >= 60)
{
if($ip != $cip)
{
$this->DelSession($code);
return false;
}
}
return true;
}
return false;
}
public function ReturnSessionData(string $sid): string
{
$data = $this->sess->get($sid);
$encoded = '';
foreach($data as $row => $value)
{
$encoded = $value.'%';
}
return substr_replace($encoded ,"", -1);
}
public function ReturnSessionUser(string $sid): string
{
$data = $this->sess->get($sid, 'user');
echo $data;
return $data;
}
public function ContinueSession(string $sid): string
{
}
public function ReturnSessionType(string $sid): string
{
$data = $this->sess->get($sid, 'type');
echo $data;
return $data;
}
}