public function redirect($url, Request $request, Response $response, $code = 302) { // prevent header attacks $url = str_replace(array("\n", "\r"), '', $url); if (!preg_match('|^[a-z]+://|', $url)) { $base = rtrim($request->getBaseUrl(), '/'); if ($base && '/' != $base) { $url = $base . '/' . ltrim($url, '/'); } else { $url = '/' . ltrim($url, '/'); } } if (!preg_match('#^(https?|ftp)://#', $url)) { $host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : ''; $proto = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== "off" ? 'https' : 'http'; $port = isset($_SERVER['SERVER_PORT']) ? $_SERVER['SERVER_PORT'] : 80; $uri = $proto . '://' . $host; if ('http' == $proto && 80 != $port || 'https' == $proto && 443 != $port) { // do not append if HTTP_HOST already contains port if (strrchr($host, ':') === false) { $uri .= ':' . $port; } } $url = $uri . '/' . ltrim($url, '/'); } $response->setRedirect($url, $code); $response->sendHeaders(); exit; }
public function handle(Request $request, Response $response, array $config) { $view = new View(__DIR__ . '/../View'); $response->setBody($view->render('index')); }