To facilitate the use of php sessions, I have rewritten a simple session method here.
Create application/libraries/Sessions. php with the following content:
01
<? Php
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
{
21
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 automatic loading in autoload. php or manually call Sessions.
Author: chory