/** * Check domain and header 301. * * @access public * @return void */ public function checkDomain() { if (RUN_MODE == 'install' or RUN_MODE == 'upgrade' or RUN_MODE == 'shell' or RUN_MODE == 'admin' or !$this->config->installed) { return true; } $http = (isset($_SERVER['HTTPS']) and strtolower($_SERVER['HTTPS']) != 'off') ? 'https://' : 'http://'; $httpHost = $this->server->http_host; $currentURI = $http . $httpHost . $this->server->request_uri; $scheme = isset($this->config->site->scheme) ? $this->config->site->scheme : 'http'; $mainDomain = isset($this->config->site->domain) ? $this->config->site->domain : ''; $mainDomain = str_replace(array('http://', 'https://'), '', $mainDomain); /* Check main domain and scheme. */ $redirectURI = $currentURI; if (strpos($redirectURI, $scheme . '://') !== 0) { $redirectURI = $scheme . substr($redirectURI, strpos($redirectURI, '://')); } if (!empty($mainDomain) and $httpHost != $mainDomain) { $redirectURI = str_replace($httpHost, $mainDomain, $redirectURI); } if ($redirectURI != $currentURI) { header301($redirectURI); } /* Check domain is allowed. */ $allowedDomains = isset($this->config->site->allowedDomain) ? $this->config->site->allowedDomain : ''; $allowedDomains = str_replace(array('http://', 'https://'), '', $allowedDomains); if (!empty($allowedDomains)) { if (strpos($allowedDomains, $httpHost) !== false) { return true; } if (!empty($mainDomain) and helper::getSiteCode($httpHost) == helper::getSiteCode($mainDomain)) { return true; } die('domain denied.'); } }
/** * Check domain and header 301. * * @access public * @return void */ public function checkDomain() { if (RUN_MODE == 'install' or RUN_MODE == 'upgrade' or RUN_MODE == 'shell' or RUN_MODE == 'admin' or !$this->config->installed) { return true; } $domains = isset($this->config->site->allowedDomain) ? $this->config->site->allowedDomain : ''; $domains = str_replace(array('http://', 'https://'), '', $domains); $mainDomain = isset($this->config->site->domain) ? $this->config->site->domain : ''; $mainDomain = str_replace(array('http://', 'https://'), '', $mainDomain); $host = $this->server->http_host; /* Check domain is allowed. */ if (!empty($domains)) { $allowed = false; $domains = explode(',', str_replace(',', ',', $domains)); $domains[] = $mainDomain; foreach ($domains as $domain) { if (empty($domain)) { continue; } if (strpos($host, $domain) !== false and substr($host, strpos($host, $domain)) == $domain) { $allowed = true; break; } } if (!$allowed) { die('domain denied.'); } } /* Check main domain. */ $redirect = false; $redirectURI = getWebRoot(true) . $this->app->getURI(); if ($mainDomain and $mainDomain != $host) { $redirect = true; $redirectURI = str_replace($host, $mainDomain, $redirectURI); } /* Check scheme. */ $scheme = isset($this->config->site->scheme) ? $this->config->site->scheme : 'http'; if (strpos($redirectURI, $scheme . '://') !== 0) { $redirect = true; $redirectURI = $scheme . substr($redirectURI, strpos($redirectURI, '://')); } if ($redirect) { header301($redirectURI); } }