-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkatorymnd_session.php
117 lines (99 loc) · 2.33 KB
/
katorymnd_session.php
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
116
<?php
class session
{
private $begin_session = false;
private $session_destroy;
/**
* start_session function
* start session
* @return void
*/
public function start_session()
{
if ($this->begin_session == false) {
session_start();
$this->begin_session = true;
}
}
// $_SESSION[$key] = $value;
public function set_session($key, $value)
{
$_SESSION[$key] = $value;
}
/**
* get_session function
*
* @param [type] $key = normal sessio
* @param boolean $second_key = array - value
* @return void
*
* example array
* $katorymnd_session->set_session('name', array(
* 'name' => 'john',
* 'number' => '123',
* ));
*
* call the session
*
* $katorymnd_session->get_session('name', 'number'); [123]
*
*
* normal example
* $katorymnd_session->set_session('names', 'smith'); // set session
*
* call the session
* $katorymnd_session->get_session('names'); [smith]
*
* check session to retrict page access
*
* if($katorymnd_session->get_session('names') == true){
*
* // login user
*
* }else{
*
* //no user session
*
* }
*/
public function get_session($key, $second_key = false)
{
if ($second_key == true) {
if (isset($_SESSION[$key][$second_key])) {
return $_SESSION[$key][$second_key];
}
} else {
if (isset($_SESSION[$key])) {
return $_SESSION[$key];
}
}
return false;
}
/**
* display_session function
*
* will display any available session if called
* this will help to know if the session is set or not
* @return void
*/
public function display_session()
{
print '<pre>';
print_r($_SESSION);
print '</pre>';
}
/**
* destroy_session function
* delete or clear any available session
* @return void
*/
public function destroy_session()
{
if ($this->begin_session == true) {
session_unset();
session_destroy();
}
}
}
$katorymnd_session = new session(); // intiatiate
$katorymnd_session->start_session();