|
1 | 1 | <?php |
2 | 2 | /** |
3 | | - * session class |
4 | | - *@Author weibo.com/yakeing |
5 | | - * |
6 | | - * set(name, value) Set up a session Value |
7 | | - * get(name) Get a session Value |
8 | | - * deletes(name) Write off a session Value |
9 | | - * destroy() End all session Value |
10 | | - * |
11 | | - *@ $expire Default server 180 minutes client end |
12 | | - *@ $uid user ID, Default automatic generation |
13 | | - * |
14 | | - * 'session_name' Can customize session's name |
15 | | - * SAE provides a solution for Memcache storage Session |
16 | | - * |
17 | | - *PHP 5.3 Edition |
18 | | - * session_set_save_handler( |
19 | | - * array($handler, 'open'), |
20 | | - * array($handler, 'close'), |
21 | | - * array($handler, 'read'), |
22 | | - * array($handler, 'write'), |
23 | | - * array($handler, 'destroy'), |
24 | | - * array($handler, 'gc') |
25 | | - * ); |
| 3 | + * SESSION CLASS |
| 4 | + * |
| 5 | + * @author http://weibo.com/yakeing |
| 6 | + * @version 1.2 |
| 7 | + * $expire Default server 180 minutes client end |
| 8 | + * $uid user ID, Default automatic generation |
| 9 | + * |
| 10 | + * 'session_name' Can customize session's name |
| 11 | + * SAE provides a solution for Memcache storage Session |
| 12 | + * |
| 13 | + * PHP 5.3 Edition |
| 14 | + * session_set_save_handler( |
| 15 | + * array($handler, 'open'), |
| 16 | + * array($handler, 'close'), |
| 17 | + * array($handler, 'read'), |
| 18 | + * array($handler, 'write'), |
| 19 | + * array($handler, 'destroy'), |
| 20 | + * array($handler, 'gc') |
| 21 | + * ); |
26 | 22 | */ |
27 | 23 | class session{ |
28 | 24 | public $mcsession = false; |
29 | | - function __construct($expire = false, $uid = false){ |
30 | | - if($this->mcsession){ |
| 25 | + |
| 26 | + //Initialization |
| 27 | + function __construct($expire = false, $uid = false, $name = "MYSESSION"){ |
| 28 | + if($this->mcsession){//PHP 5.6 Edition |
31 | 29 | $handler = new sinacloud\sae\MemcacheSessionHandler(); |
32 | | - session_set_save_handler($handler, true);//PHP 5.6 Edition |
| 30 | + session_set_save_handler($handler, true); |
33 | 31 | } |
34 | 32 | session_cache_limiter('private'); |
35 | 33 | if(is_int($expire)){ |
36 | 34 | session_cache_expire($expire); |
37 | 35 | session_set_cookie_params($expire*60); |
38 | 36 | } |
39 | 37 | if(!empty($uid)) session_id($uid); |
40 | | - session_name("MYSESSION"); |
| 38 | + session_name($name); |
41 | 39 | session_start(); |
42 | | - } |
| 40 | + } //END __construct |
43 | 41 |
|
44 | | - function set($name, $value){ |
45 | | - $_SESSION[$name] = $value; |
46 | | - } |
| 42 | + //Set up a session Value |
| 43 | + function Set($name, $value){ |
| 44 | + if(is_scalar($value)){ |
| 45 | + $_SESSION[$name] = $value; |
| 46 | + return true; |
| 47 | + } |
| 48 | + return false; |
| 49 | + } //END set |
47 | 50 |
|
48 | | - function get($name){ |
| 51 | + //Get a session Value |
| 52 | + function Get($name){ |
49 | 53 | if(isset($_SESSION[$name])){ |
50 | 54 | return $_SESSION[$name]; |
51 | 55 | }else{ |
52 | | - return null; |
| 56 | + return false; |
53 | 57 | } |
54 | | - } |
| 58 | + } //END get |
55 | 59 |
|
56 | | - function deletes($name){ |
| 60 | + //Write off a session Value |
| 61 | + function Deletes($name){ |
57 | 62 | if(isset($_SESSION[$name])){ |
58 | 63 | unset($_SESSION[$name]); |
| 64 | + return true; |
59 | 65 | } |
60 | | - } |
| 66 | + return false; |
| 67 | + } //END deletes |
61 | 68 |
|
62 | | - function destroy(){ |
| 69 | + //End all session Value |
| 70 | + //Use setcookie() Delete the client's SESSION ID |
| 71 | + function Destroy(){ |
63 | 72 | session_destroy(); |
64 | | - } |
65 | | - |
66 | | - function __destruct(){} |
| 73 | + } //END destroy |
67 | 74 | } |
68 | | -?> |
|
0 commit comments