This repository has been archived by the owner on Dec 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.session.php
executable file
·66 lines (60 loc) · 2.05 KB
/
class.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
<?php
/*======================================================================*\
|| #################################################################### ||
|| # PHP Utilities Alpha 2 # ||
|| # ---------------------------------------------------------------- # ||
|| # Useful Everyday PHP classes, that work as one! # ||
|| # ---------------------------------------------------------------- # ||
|| # All PHP code in this file is ©2014 VisionWare Studios # ||
|| # This script is released under The MIT License. # ||
|| # # ||
|| # --------------- PHP VERSION 5.5.0 OR GREATER ----------------- # ||
|| # # ||
|| # http://visionware-studios.com # ||
|| #################################################################### ||
\*======================================================================*/
class Session
{
private $_logged_in = FALSE;
public $user_id;
public $username;
public function __construct()
{
session_start();
$this->check_login();
}
public function is_logged_in()
{
return $this->_logged_in;
}
public function login($user)
{
if ($user)
{
$this->user_id = $_SESSION['user_id'];
$this->username = $_SESSION['username'];
$this->_logged_in = TRUE;
}
}
public function logout()
{
unset($_SESSION['user_id']);
unset($this->user_id);
$this->_logged_in = FALSE;
}
private function check_login()
{
if (isset($_SESSION['user_id']))
{
$this->user_id = $_SESSION['user_id'];
$this->username = $_SESSION['username'];
$this->_logged_in = TRUE;
}
else
{
unset($this->user_id);
unset($this->username);
$this->_logged_in = FALSE;
}
}
}