public static function AGet($sUrl = '') { if (!isset(self::$s_aResults[$sUrl])) { if ('' === $sUrl) { $host = Ko_Web_Request::SHttpHost(); $uri = Ko_Web_Request::SRequestUri(); } else { $info = parse_url($sUrl); $host = isset($info['port']) ? $info['host'] . ':' . $info['port'] : $info['host']; $uri = isset($info['query']) ? $info['path'] . '?' . $info['query'] : $info['path']; } self::$s_aResults[$sUrl] = self::_AGet($host, $uri); } return self::$s_aResults[$sUrl]; }
/** * @return self */ private static function _OGetConfig($host) { if (is_null($host)) { $host = Ko_Web_Request::SHttpHost(); } if (!isset(self::$s_aHostConfig[$host])) { self::$s_aHostConfig[$host] = new self(); if (isset(self::$s_aConfig['global'][$host])) { $appname = self::$s_aConfig['global'][$host]; self::$s_aHostConfig[$host]->_sAppName = $appname; if (isset(self::$s_aConfig['app_' . $appname])) { self::$s_aHostConfig[$host]->_sDocumentRoot = strval(self::$s_aConfig['app_' . $appname]['documentroot']); self::$s_aHostConfig[$host]->_sRewriteConf = strval(self::$s_aConfig['app_' . $appname]['rewriteconf']); self::$s_aHostConfig[$host]->_sRewriteCache = strval(self::$s_aConfig['app_' . $appname]['rewritecache']); } } } return self::$s_aHostConfig[$host]; }
/** * 通过设置 POST 时允许的 ref 域名来保证基本的安全 * * @param array $aPostAllowRefDomain 只允许ref为同样的域名 array(), * 允许ref为任意域名 array('*'), * 允许ref为指定某些域名 array('*.test.com', 'www.demo.com'), * ref为空被视为可以访问不进行这些检查 */ public static function BCheckMethod($aPostAllowRefDomain = array()) { if ('POST' === Ko_Web_Request::SRequestMethod()) { $referer = Ko_Web_Request::SHttpReferer(); if (strlen($referer)) { $refinfo = parse_url(strtolower($referer)); if (empty($aPostAllowRefDomain)) { list($host, $port) = explode(':', Ko_Web_Request::SHttpHost(), 2); if ($refinfo['host'] !== $host) { return false; } } else { if (!self::_BCheckDomains($refinfo['host'], $aPostAllowRefDomain)) { return false; } } } } return true; }
/** * @return self */ private static function _OGetConfig($host, &$uri) { if (is_null($host)) { $host = Ko_Web_Request::SHttpHost(); } if (is_null($uri)) { $uri = Ko_Web_Request::SRequestUri(); } if (false === strpos($uri, '?')) { $path = $uri; $query = ''; } else { list($path, $query) = explode('?', $uri, 2); $query = '?' . $query; } $key = $host . $path; if (!isset(self::$s_aConfigCache[$key])) { $path = rtrim($key, '/'); $succ = false; while (false !== ($pos = strrpos($path, '/'))) { if ($succ = self::_BLoadConfig($key, $path, false)) { break; } $path = rtrim(substr($path, 0, $pos), '/'); } if (!$succ) { self::_BLoadConfig($key, $path, true); } $rewriteuri = substr($key, strlen($path)); if (0 === strlen($rewriteuri)) { $rewriteuri = '/'; } self::$s_aConfigCache[$key]->_sRewriteUri = $rewriteuri . $query; } $uri = self::$s_aConfigCache[$key]->_sRewriteUri; return self::$s_aConfigCache[$key]; }