To facilitate the use of PHP's session, I have rewritten a simple session method here.
Create a new application/libraries/sessions.php with the following content:
01
02
if (!defined (' BasePath ')) exit (' No Direct script access allowed ');
03
04
/**
05
* Reconstruct the Session class
06
* @author Chory
07
* @version 1.0
08
* @copyright 2011/6/12
09
*/
10
Class sessions{
11
private static $instances;
12
private static function instance ()
13
{
14
if (Empty (self:: $instances)) {
15
@self:: $instances = &load_class (' session ');
16
}
17
Return self:: $instances;
18
}
19
public static function set ($key, $value = "")
20
{
21st
Self::instance (), Set_userdata (Array ($key = $value));
22
}
23
public static function Get ($key = null)
24
{
25
if ($key)
26
{
27
Return Self::instance (), UserData ($key);
28
}
29
Else
30
{
31
Return Self::instance (), All_userdata ();
32
}
33
}
34
public static function _unset ($key) {
35
Self::instance (), Unset_userdata ($key);
36
}
37
public static function Destroy () {
38
Self::instance (), Sess_destroy ();
39
}
40
}
Application Method:
Sessions::set ("username", "admin");
Sessions::get ("username");
You can set up automatic loading in autoload.php, or call sessions manually
Author: chory
http://www.bkjia.com/PHPjc/478135.html www.bkjia.com true http://www.bkjia.com/PHPjc/478135.html techarticle to facilitate the use of PHP's session, I have rewritten a simple session method here. Create a new application/libraries/sessions.php with the following:!defined php (basepath) ...