/** * Send redirect response */ public function redirect($location = '', $code = 302, $delay = 1) { $current = Server::getUrl(); $location = Sanitize::toUrl($location); $path1 = Sanitize::toPath(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)); $path2 = Sanitize::toPath(parse_url($location, PHP_URL_PATH)); $code = is_numeric($code) ? intval($code) : 302; if (Validate::isExternal($location) || $path1 !== $path2) { $this->flushHeaders(); $this->flushContents(); $this->setText($code, ''); $this->setHeader('Location', $location, true); $this->setHeader('Connection', 'close', true); $this->send($delay); } throw new Exception('Redirect aborted, from (' . $current . ') to (' . $location . ').'); }