-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsession.php
82 lines (76 loc) · 2.35 KB
/
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
<?php
/**
* SESSION
*
* author http://weibo.com/yakeing
* version 2.1
* $expire Default server 180 minutes client end
* $id user ID, Default automatic generation
* $name Default PHPSESSID
*
*/
namespace php_session;
class session{
public $id = '';
//__construct
public function __construct($expire = false, $id = '', $name = "PHPSESSID", $limiter = 'private', $handler = null){
if($this->IsSessionStarted()){
if(!is_null($handler)) session_set_save_handler($handler, true);
session_cache_limiter($limiter);
if(is_int($expire)){
session_cache_expire($expire);
session_set_cookie_params($expire*60);
}
if(!empty($id)) session_id($id);
session_name($name);
session_start();
}
$this->id = session_id();
} //END __construct
// session IsSessionStarted
/*
0 ----> PHP_SESSION_DISABLED if sessions are disabled.
1 ----> PHP_SESSION_NONE if sessions are enabled, but none exists.
2 ----> PHP_SESSION_ACTIVE if sessions are enabled, and one exists.
*/
private function IsSessionStarted(){
if(php_sapi_name() === 'cli') return true;
if(version_compare(phpversion(), '5.4.0', '>=')){
return (session_status() === PHP_SESSION_ACTIVE ? false : true);
}else{
return (session_id() === '' ? true : false);
}
}//END IsSessionStarted
//Set up a session Value
public function Set($name, $value){
if(is_scalar($value) || is_array( $value)){
$_SESSION[$name] = $value;
return true;
}
return false;
} //END set
//Get a session Value
public function Get($name){
if(isset($_SESSION[$name])){
return $_SESSION[$name];
}else{
return false;
}
} //END get
//Write off a session Value
public function Delete($name){
if(isset($_SESSION[$name])){
unset($_SESSION[$name]);
}
return true;
} //END delete
//function frees all session variables currently registered.
public function Unsets(){
session_unset();
} //END Unset
//End all session Value
//Use setcookie() Delete the client's SESSION ID
public function Destroy(){
return session_destroy();
} //END destroy
}