From cb1021da880b5200fdfe87e43d96a86de811e482 Mon Sep 17 00:00:00 2001 From: xue <> Date: Mon, 19 Jun 2006 12:37:59 +0000 Subject: Fixed #244, #245. --- framework/Web/THttpRequest.php | 18 +++++++++++++++++- framework/Web/THttpResponse.php | 5 ++++- 2 files changed, 21 insertions(+), 2 deletions(-) (limited to 'framework') diff --git a/framework/Web/THttpRequest.php b/framework/Web/THttpRequest.php index 4e04ecca..b908db53 100644 --- a/framework/Web/THttpRequest.php +++ b/framework/Web/THttpRequest.php @@ -259,7 +259,7 @@ class THttpRequest extends TApplicationComponent implements IteratorAggregate,Ar */ public function getIsSecureConnection() { - return !empty($_SERVER['HTTPS']); + return isset($_SERVER['HTTPS']) && strcasecmp($_SERVER['HTTPS'],'off'); } /** @@ -286,6 +286,14 @@ class THttpRequest extends TApplicationComponent implements IteratorAggregate,Ar return $this->_requestUri; } + /** + * @return string schema and hostname of the requested URL + */ + public function getBaseUrl() + { + return ($this->getIsSecureConnection() ? "https://" : "http://") . $_SERVER ['HTTP_HOST']; + } + /** * @return string entry script URL (w/o host part) */ @@ -294,6 +302,14 @@ class THttpRequest extends TApplicationComponent implements IteratorAggregate,Ar return $_SERVER['SCRIPT_NAME']; } + /** + * @return string entry script URL (w/ host part) + */ + public function getAbsoluteApplicationUrl() + { + return $this->getBaseUrl() . $this->getApplicationUrl(); + } + /** * @return string application entry script file path (processed w/ realpath()) */ diff --git a/framework/Web/THttpResponse.php b/framework/Web/THttpResponse.php index 5a3ff99d..f455f48d 100644 --- a/framework/Web/THttpResponse.php +++ b/framework/Web/THttpResponse.php @@ -274,12 +274,15 @@ class THttpResponse extends TModule implements ITextWriter /** * Redirects the browser to the specified URL. * The current application will be terminated after this method is invoked. - * @param string URL to be redirected to + * @param string URL to be redirected to. If the URL is a relative one, the base URL of + * the current request will be inserted at the beginning. */ public function redirect($url) { if(!$this->getApplication()->getRequestCompleted()) $this->getApplication()->onEndRequest(); + if($url[0]==='/') + $url=$this->getRequest()->getBaseUrl().$url; header('Location:'.$url); exit(); } -- cgit v1.2.3