/** * 构造函数 */ public function __construct() { if ($this->Args('isajax', 'int') == 1) { $this->isAjax = 1; } if (!self::isLogin()) { if ($this->isAjax) { $this->displayAjax(false, '您还没有登陆,请先登录'); } return CResponse::getInstance()->redirect(array('c' => 'base', 'a' => 'index')); } $status = self::checkRight(); // 用户资源 if ($this->layout == 'layout_main') { $userData = CSession::get('user'); $this->assign('userdata', $userData); } // 检查权限 if (false == $status) { // 判断请求方式 if ($this->isAjax) { $this->displayAjax(false, '您没有权限执行此操作!'); } // 分析错误信息 $data['from'] = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''; // ip归属地 $data['ip'] = CRequest::getIp(); $data['ipArea'] = IPArea::getArea(CRequest::getIp()); $data['agent'] = CRequest::getAgent(); $this->assign('data', $data); $this->display('alert/noright'); exit; } }
/** * 获取请求并处理 */ public function GetRequest() { //处理请求 ob_start(); CRequest::getInstance()->run(); //发送响应 CResponse::getInstance()->send(); ob_end_flush(); }
/** * 请求结束 */ public static function webShutdown() { //传递引起脚本中断的致命错误 $lastError = error_get_last(); if (!empty($lastError) && in_array($lastError['type'], array(E_USER_ERROR, E_PARSE, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR, E_ERROR))) { CException::getTopErrors($lastError['type'], $lastError['message'], $lastError['file'], $lastError['line']); } //脚本因错误而中断 if (true == CException::hasFatalErrors()) { //最后发生的错误 $lastError = error_get_last(); //设置503请求头 CResponse::getInstance()->setHttpCode(503, false); } //触发执行结束钩子函数 CHooks::callHooks(HOOKS_SYSTEM_SHUTDOWN, CException::$errorList); //是否使用CMyFrame 默认错误呈现 if (true == CException::getErrorShow()) { //使用CMyFrame 默认进行错误呈现 CException::showErrorsView(); } }
/** * 关闭GET请求 */ public static function disableGET() { if (!isset($_SERVER['REQUEST_METHOD'])) { trigger_error('服务器拒绝执行该方式的请求', E_ALL); } $requestType = $_SERVER['REQUEST_METHOD']; if ('GET' == $requestType) { CResponse::getInstance()->setHttpCode(405, false); throw new CRouteException('该地址不支持GET请求'); } }
/** * 退出 */ public function Action_Logout() { CSession::del('user'); CResponse::getInstance()->redirect(array('c' => 'base', 'a' => 'index')); }