CodeIgniter Session Refactoring _php Tutorial

Source: Internet
Author: User
Tags codeigniter
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) ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.