예제 #1
0
 /**
  * 创建Session
  *
  * @return  void
  */
 public function create()
 {
     session_name(Session::$config['name']);
     $this->destroy();
     $cookie_config = Core::config('cookie');
     # 这里对IP+非80端口的需要特殊处理下,经试验,当这种情况下,设置session id的cookie的话会失败
     if (preg_match('#^([0-9]+.[0-9]+.[0-9]+.[0-9]+):[0-9]+$#', $cookie_config['domain'], $m)) {
         # IP:PORT 方式
         $cookie_config['domain'] = $m[1];
     }
     $s_name = session_name();
     if (Session::$config['type'] == 'url') {
         $old_sid = HttpIO::COOKIE($s_name);
     } else {
         $old_sid = HttpIO::COOKIE($s_name);
     }
     if ($old_sid) {
         # 校验Session ID
         if (!Session::check_session_id($old_sid)) {
             # 如果检验的Session ID不合法,则重新生成一个
             session_id(Session::create_session_id());
         }
     } else {
         # 设置Session ID
         session_id(Session::create_session_id());
     }
     # Session ID 通过uri传递
     if (Session::$config['type'] == 'url') {
         @ini_set('session.use_cookies', 0);
         @ini_set('session.use_only_cookies', 0);
     } else {
         session_set_cookie_params($cookie_config['httponly'] ? 0 : Session::$config['expiration'], $cookie_config['path'], $cookie_config['domain'], $cookie_config['secure'], $cookie_config['httponly']);
     }
     session_start();
 }
예제 #2
0
 /**
  * Create a new session.
  *
  * @return  void
  */
 public function create()
 {
     $cookie_config = Core::config('cookie');
     $_SESSION = array();
     switch (Session::$config['type']) {
         case 'auto':
             $sid = HttpIO::REQUEST($this->session_name);
             break;
         case 'url':
             $sid = HttpIO::GET($this->session_name);
             break;
         default:
             $sid = HttpIO::COOKIE($this->session_name);
             break;
     }
     if (!$sid || !Session::check_session_id($sid)) {
         $sid = Session::create_session_id();
         if (Session::$config['type'] != 'url') {
             # 将session存入cookie
             Core::cookie()->set($this->session_name, $sid, !Session::$config['httponly'] && Session::$config['expiration'] > 0 ? Session::$config['expiration'] : null, $cookie_config['path'], $cookie_config['domain'], $cookie_config['secure'], Session::$config['httponly']);
         }
     }
     # 添加URL处理自动追加SESSION ID参数
     if (Session::$config['type'] == 'url') {
         Core::add_url_args(Session::$config['name'], $sid);
     }
     # 调试模式设置Session模式,避免开启缓存模式时获取不到Session
     if (IS_DEBUG) {
         $this->driver()->session_mode(true);
     }
     $_SESSION = $this->driver()->get($sid);
     if (IS_DEBUG) {
         $this->driver()->session_mode(false);
     }
     if (!is_array($_SESSION)) {
         $_SESSION = array();
     }
     # 将获取的值序列化MD5值
     Session_Driver_Cache::$OLD_SESSION_MD5 = md5(serialize($_SESSION));
     # 当前session id
     Session_Driver_Cache::$Session_ID = $sid;
 }
예제 #3
0
 /**
  * 创建Session
  *
  * @return  void
  */
 public function create()
 {
     session_name(Session::$config['name']);
     $this->destroy();
     $cookie_config = Core::config('cookie');
     # 这里对IP+非80端口的需要特殊处理下,经试验,当这种情况下,设置session id的cookie的话会失败
     if (preg_match('#^([0-9]+.[0-9]+.[0-9]+.[0-9]+):[0-9]+$#', $cookie_config['domain'], $m)) {
         # IP:PORT 方式
         $cookie_config['domain'] = $m[1];
     }
     $s_name = session_name();
     switch (Session::$config['type']) {
         case 'auto':
             $sid = HttpIO::REQUEST($s_name);
             break;
         case 'url':
             $sid = HttpIO::GET($s_name);
             break;
         default:
             $sid = HttpIO::COOKIE($s_name);
             break;
     }
     if (!$sid || !Session::check_session_id($sid)) {
         # 如果检验的Session ID不合法,则重新生成一个
         session_id(Session::create_session_id());
     } else {
         session_id($sid);
     }
     # Session ID 通过uri传递
     if (Session::$config['type'] == 'url') {
         @ini_set('session.use_only_cookies', 0);
     } else {
         session_set_cookie_params(Session::$config['httponly'] ? 0 : (int) Session::$config['expiration'], $cookie_config['path'], $cookie_config['domain'], $cookie_config['secure'], Session::$config['httponly']);
     }
     session_start();
 }
예제 #4
0
 /**
  * 系统错误,可直接将Exception对象传给$msg
  * @param string/Exception $msg
  */
 public static function show_500($msg = null)
 {
     Core::close_buffers(false);
     # 避免输出的CSS头试抛出页面无法显示
     @header('Content-Type: text/html;charset=' . Core::config('charset'), true);
     HttpIO::$status = 500;
     HttpIO::send_headers();
     if (null === $msg) {
         $msg = __('Internal Server Error');
     }
     if (IS_DEBUG && class_exists('DevException', false)) {
         if ($msg instanceof Exception) {
             $e = $msg;
         } else {
             $e = new Exception($msg);
         }
         echo DevException::exception_handler($e, true);
         exit;
     }
     if (IS_CLI) {
         echo "", $msg, CRLF, "", CRLF;
         exit;
     }
     try {
         if ($msg instanceof Exception) {
             $error = $msg->getMessage();
             $trace_obj = $msg;
         } else {
             $error = $msg;
             $trace_obj = new Exception($msg);
         }
         $error_config = Core::config('error500');
         $view = new View('error/500');
         if ($error_config && isset($error_config['close']) && $error_config['close'] == true) {
             # 不记录
             $view->error_saved = false;
             $error_no = '';
         } else {
             $trace_array = array('project' => Core::$project, 'admin_mode' => IS_ADMIN_MODE, 'uri' => HttpIO::$uri, 'url' => HttpIO::PROTOCOL . $_SERVER['HTTP_HOST'] . $_SERVER["REQUEST_URI"], 'post' => HttpIO::POST(null, HttpIO::PARAM_TYPE_OLDDATA), 'get' => $_SERVER['QUERY_STRING'], 'cookie' => HttpIO::COOKIE(null, HttpIO::PARAM_TYPE_OLDDATA), 'client_ip' => HttpIO::IP, 'user_agent' => HttpIO::USER_AGENT, 'referrer' => HttpIO::REFERRER, 'server_ip' => $_SERVER["SERVER_ADDR"]);
             $date = @date('Y-m-d');
             $no = strtoupper(substr(md5(serialize($trace_array)), 10, 10));
             $error_no = $date . '-' . $no;
             # 其它数据
             $trace_array['server_name'] = function_exists('php_uname') ? php_uname('a') : 'unknown';
             $trace_array['time'] = TIME;
             $trace_array['use_time'] = microtime(1) - START_TIME;
             $trace_array['trace'] = (string) $trace_obj;
             $trace_string = Core::json_encode($trace_array);
             $view->error_saved = true;
             # 记录错误日志
             try {
                 if (isset($error_config['save_type']) && $error_config['save_type']) {
                     $save_type = $error_config['save_type'];
                 } else {
                     $save_type = 'file';
                 }
                 if ($save_type === 'file') {
                     # 文件模式
                     $write_mode = Core::config('file_write_mode');
                     if (preg_match('#^(db|cache|fluent)://(([a-z0-9\\.\\-_]+)(?:\\:|/)([a-z0-9_]+))$#i', $write_mode, $m)) {
                         $save_type = $m[1];
                         $error_config['server'] = $m[2];
                         $error_config['type_config'] = $m[3];
                     }
                 }
                 switch ($save_type) {
                     case 'database':
                         $obj = $error_config['type_config'] ? new Database($error_config['type_config']) : new Database();
                         $data = array('time' => strtotime($date . ' 00:00:00'), 'no' => $no, 'log' => $obj->is_support_object_value() ? $trace_array : $trace_string, 'expire_time' => TIME + 7 * 86400);
                         $obj->insert('error500_log', $data);
                         break;
                     case 'cache':
                         $obj = $error_config['type_config'] ? new Cache($error_config['type_config']) : new Cache();
                         if (!$obj->get($error_no)) {
                             $obj->set($error_no, $trace_string, 7 * 86400);
                         }
                         break;
                     case 'fluent':
                         if (strpos($error_config['server'], ':') !== false) {
                             $fd_server = 'tcp://' . $error_config['server'];
                         } else {
                             $fd_server = 'udp://' . $error_config['server'];
                         }
                         $obj = Fluent::instance($fd_server);
                         $obj->push('system.error500', $trace_array);
                         break;
                     default:
                         $file = DIR_LOG . 'error500' . DS . str_replace('-', DS, $date) . DS . $no . '.log';
                         if (!is_file($file)) {
                             File::create_file($file, date('Y-m-d\\TH:i:s') . ' - ' . $trace_string, null, null, $error_config['type_config'] ? $error_config['type_config'] : 'default');
                         }
                         break;
                 }
             } catch (Exception $e) {
             }
         }
         $view->error_no = $error_no;
         $view->error = $error;
         $view->render(true);
     } catch (Exception $e) {
         list($REQUEST_URI) = explode('?', $_SERVER['REQUEST_URI'], 2);
         $REQUEST_URI = htmlspecialchars(rawurldecode($REQUEST_URI));
         echo '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">' . CRLF . '<html>' . CRLF . '<head>' . CRLF . '<title>Internal Server Error</title>' . CRLF . '</head>' . CRLF . '<body>' . CRLF . '<h1>Internal Server Error</h1>' . CRLF . '<p>The requested URL ' . $REQUEST_URI . ' was error on this server.</p>' . CRLF . '<hr />' . CRLF . $_SERVER['SERVER_SIGNATURE'] . '<br/><br/><br/>' . CRLF . 'Powered by MyQEE V' . Core::VERSION . CRLF . '</body>' . CRLF . '</html>';
     }
     exit;
 }
예제 #5
0
파일: core.class.php 프로젝트: myqee/core
 /**
  * 系统错误,可直接将Exception对象传给$msg
  * @param string/Exception $msg
  */
 public static function show_500($msg = null)
 {
     Core::close_buffers(false);
     # 避免输出的CSS头试抛出页面无法显示
     @header('Content-Type: text/html;charset=' . Core::config('core.charset'), true);
     HttpIO::$status = 500;
     HttpIO::send_headers();
     if (null === $msg) {
         $msg = __('Internal Server Error');
     }
     if (IS_DEBUG && class_exists('ErrException', false)) {
         if ($msg instanceof Exception) {
             throw $msg;
         } else {
             throw new Exception($msg, 0);
         }
     }
     if (IS_CLI) {
         echo "";
         if ($msg instanceof Exception) {
             echo $msg->getMessage() . CRLF;
         } else {
             echo $msg . CRLF;
         }
         echo "";
         echo CRLF;
         exit;
     }
     try {
         if ($msg instanceof Exception) {
             $error = $msg->getMessage();
             $trace_obj = $msg;
         } else {
             $error = $msg;
             $trace_obj = new Exception($msg);
         }
         $error_config = Core::config('core.error500');
         $view = new View('error/500');
         if ($error_config && isset($error_config['close']) && $error_config['close'] == true) {
             # 不记录
             $view->error_saved = false;
         } else {
             $trace_array = array('project' => Core::$project, 'uri' => HttpIO::$uri, 'url' => HttpIO::PROTOCOL . $_SERVER['HTTP_HOST'] . $_SERVER["REQUEST_URI"], 'post' => HttpIO::POST(null, HttpIO::PARAM_TYPE_OLDDATA), 'get' => $_SERVER['QUERY_STRING'], 'cookie' => HttpIO::COOKIE(null, HttpIO::PARAM_TYPE_OLDDATA), 'client_ip' => HttpIO::IP, 'user_agent' => HttpIO::USER_AGENT, 'referrer' => HttpIO::REFERRER, 'server_ip' => $_SERVER["SERVER_ADDR"], 'trace' => $trace_obj->__toString());
             $date = @date('Y-m-d');
             $no = strtoupper(substr(md5(serialize($trace_array)), 10, 10));
             $error_no = $date . '-' . $no;
             # 其它数据
             $trace_array['server_name'] = function_exists('php_uname') ? php_uname('a') : 'unknown';
             $trace_array['time'] = TIME;
             $trace_array['use_time'] = microtime(1) - START_TIME;
             $trace_array['trace'] = $trace_obj;
             $trace_data = base64_encode(gzcompress(serialize($trace_array), 9));
             unset($trace_array);
             $view->error_saved = true;
             # 记录错误日志
             try {
                 if (isset($error_config['save_type']) && $error_config['save_type']) {
                     $save_type = $error_config['save_type'];
                 } else {
                     $save_type = 'file';
                 }
                 if ($save_type == 'file') {
                     # 文件模式
                     $write_mode = Core::config('core.file_write_mode');
                     if (preg_match('#^(db|cache)://([a-z0-9_]+)/([a-z0-9_]+)$#i', $write_mode, $m)) {
                         $save_type = $m[1];
                         $error_config['type_config'] = $m[2];
                     }
                 }
                 switch ($save_type) {
                     case 'database':
                         $obj = $error_config['type_config'] ? new Database($error_config['type_config']) : new Database();
                         $data = array('time' => strtotime($date . ' 00:00:00'), 'no' => $no, 'log' => $trace_data, 'expire_time' => TIME + 7 * 86400);
                         $obj->insert('error500_log', $data);
                         break;
                     case 'cache':
                         $obj = $error_config['type_config'] ? new Cache($error_config['type_config']) : new Cache();
                         if (!$obj->get($error_no)) {
                             $obj->set($error_no, $trace_data, 7 * 86400);
                         }
                         break;
                     default:
                         $file = DIR_LOG . 'error500' . DS . str_replace('-', DS, $date) . DS . $no . '.log';
                         if (!is_file($file)) {
                             File::create_file($file, $trace_data, null, null, $error_config['type_config'] ? $error_config['type_config'] : 'default');
                         }
                         break;
                 }
             } catch (Exception $e) {
             }
         }
         $view->error_no = $error_no;
         $view->error = $error;
         $view->render(true);
     } catch (Exception $e) {
         list($REQUEST_URI) = explode('?', $_SERVER['REQUEST_URI'], 2);
         $REQUEST_URI = htmlspecialchars(rawurldecode($REQUEST_URI));
         echo '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">' . CRLF . '<html>' . CRLF . '<head>' . CRLF . '<title>Internal Server Error</title>' . CRLF . '</head>' . CRLF . '<body>' . CRLF . '<h1>' . __('Internal Server Error') . '</h1>' . CRLF . '<p>The requested URL ' . $REQUEST_URI . ' was error on this server.</p>' . CRLF . '<hr />' . CRLF . $_SERVER['SERVER_SIGNATURE'] . CRLF . '</body>' . CRLF . '</html>';
     }
     exit;
 }