public static function GetCurrentURL($include_querystring = true, $append_post_vars = false)
	{
		$server_protocol = isset($_SERVER["SERVER_PROTOCOL"]) ? $_SERVER["SERVER_PROTOCOL"] : "";
		$http_host = isset($_SERVER["HTTP_HOST"]) ? $_SERVER["HTTP_HOST"] : "";
		$server_port = isset($_SERVER["SERVER_PORT"]) ? $_SERVER["SERVER_PORT"] : "";

		$protocol = substr($server_protocol, 0, strpos($server_protocol, "/"))
			. (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on" ? "S" : "");
		$port = "";

		$domainport = explode(":",$http_host);
		$domain = $domainport[0];

		$port = (isset($domainport[1])) ? $domainport[1] : $server_port;

		// ports 80 and 443 are generally not included in the url
		$port = ($port == "" || $port == "80" || $port == "443") ? "" : (":" . $port);


		if (isset($_SERVER['REQUEST_URI']))
		{
			// REQUEST_URI is more accurate but isn't always defined on windows
			// in particular for the format http://www.domain.com/?var=val
			$pq = explode("?",$_SERVER['REQUEST_URI'],2);
			$path = $pq[0];
			$qs = isset($pq[1]) ? "?" . $pq[1] : "";
		}
		else
		{
			// otherwise use SCRIPT_NAME & QUERY_STRING
			$path = isset($_SERVER['SCRIPT_NAME']) ? $_SERVER['SCRIPT_NAME'] : "";
			$qs = isset($_SERVER['QUERY_STRING']) ? "?" . $_SERVER['QUERY_STRING'] : "";
		}

		// if we also want the post variables appended we can get them as a querystring from php://input
		if ($append_post_vars && isset($_POST))
		{
			$post = self::GetBody();
			$qs .= $qs ? "&$post" : "?$post";
		}

		$url = strtolower($protocol) . "://" . $domain . $port . $path . ($include_querystring ? $qs : "");

		return $url;
	}