Cml\Session::init PHP Метод

init() публичный статический Метод

初始化
public static init ( )
    public static function init()
    {
        $cmlSession = new Session();
        $cmlSession->lifeTime = ini_get('session.gc_maxlifetime');
        if (Config::get('session_user_LOC') == 'db') {
            $cmlSession->handler = Model::getInstance()->db();
        } else {
            $cmlSession->handler = Model::getInstance()->cache();
        }
        ini_set('session.save_handler', 'user');
        session_module_name('user');
        session_set_save_handler([$cmlSession, 'open'], [$cmlSession, 'close'], [$cmlSession, 'read'], [$cmlSession, 'write'], [$cmlSession, 'destroy'], [$cmlSession, 'gc']);
        ini_get('session.auto_start') || session_start();
        //自动开启session,必须在session_set_save_handler后面执行
    }

Usage Example

Пример #1
0
 /**
  * 运行对应的控制器
  *
  * @return void
  */
 public final function runAppController()
 {
     //检测csrf跨站攻击
     Secure::checkCsrf(Config::get('check_csrf'));
     // 关闭GPC过滤 防止数据的正确性受到影响 在db层防注入
     if (get_magic_quotes_gpc()) {
         Secure::stripslashes($_GET);
         Secure::stripslashes($_POST);
         Secure::stripslashes($_COOKIE);
         Secure::stripslashes($_REQUEST);
         //在程序中对get post cookie的改变不影响 request的值
     }
     //session保存方式自定义
     if (Config::get('session_user')) {
         Session::init();
     } else {
         ini_get('session.auto_start') || session_start();
         //自动开启session
     }
     header('Cache-control: ' . Config::get('http_cache_control'));
     // 页面缓存控制
     //如果有子类中有init()方法 执行Init() eg:做权限控制
     if (method_exists($this, "init")) {
         $this->init();
     }
     //根据动作去找对应的方法
     $method = Route::$urlParams['action'];
     if (method_exists($this, $method)) {
         $this->{$method}();
     } elseif ($GLOBALS['debug']) {
         Cml::montFor404Page();
         throwException(Lang::get('_ACTION_NOT_FOUND_', Route::$urlParams['action']));
     } else {
         Cml::montFor404Page();
         Response::show404Page();
     }
 }