31 public static function sslOn (): bool
33 if (isset($_SERVER[
'HTTP_X_FORWARDED_PROTO'])) {
34 return (strcasecmp($_SERVER[
'HTTP_X_FORWARDED_PROTO'],
'https') == 0);
36 if (isset($_SERVER[
'HTTPS'])) {
37 return (strcasecmp($_SERVER[
'HTTPS'],
'on') == 0);
42 protected static function gatherInfos (): array
45 if (static::sslOn()) {
49 if (!empty($_SERVER[
'HTTP_X_FORWARDED_HOST'])) {
50 $host = $_SERVER[
'HTTP_X_FORWARDED_HOST'];
51 if (isset($_SERVER[
'HTTP_X_FORWARDED_PROTO'])) {
52 $protocol = $_SERVER[
'HTTP_X_FORWARDED_PROTO'];
54 if (isset($_SERVER[
'HTTP_X_FORWARDED_PORT'])) {
55 $port = $_SERVER[
'HTTP_X_FORWARDED_PORT'];
57 $port = ($protocol ===
'http' ? 80 : 443);
60 if (!empty($_SERVER[
'HTTP_HOST'])) {
61 $host = $_SERVER[
'HTTP_HOST'];
63 $host = $_SERVER[
'SERVER_NAME'];
65 $port = $_SERVER[
'SERVER_PORT'];
68 return [$protocol, $host, $port];
75 list(, $host, $port) = static::gatherInfos();
76 $ssl =
'https://'.$host;
78 if (!empty($_SERVER[
'REQUEST_URI'])) {
79 $ssl .= $_SERVER[
'REQUEST_URI'];
80 } elseif (!empty($_SERVER[
'PATH_INFO'])) {
81 $ssl .= $_SERVER[
'PATH_INFO'];
83 $ssl .= $_SERVER[
'PHP_SELF'];
90 public static function getPageURL ($queryString = FALSE): string
92 list($protocol, $host, $port) = static::gatherInfos();
94 $pageURL = $protocol.
'://'.$host;
95 if ((($protocol ==
'http') && ($port !=
'80')) || (($protocol ==
'https') && ($port !=
'443'))) {
96 $pageURL .=
':'.$port;
98 if (!empty($_SERVER[
'REQUEST_URI']) && $queryString) {
99 $pageURL .= $_SERVER[
'REQUEST_URI'];
100 } elseif (!empty($_SERVER[
'PATH_INFO'])) {
101 $pageURL .= $_SERVER[
'PATH_INFO'];
103 $pageURL .= $_SERVER[
'PHP_SELF'];
113 list($protocol, $host, $port) = static::gatherInfos();
115 if ((($protocol ==
'http') && ($port !=
'80')) || (($protocol ==
'https') && ($port !=
'443'))) {
126 return preg_replace(
'|/[^/]*$|', $path, static::getPageURL(FALSE));
static getHostName()
Returns hostname to identify this website.
Class URL Static methods to get/build URLs.
static getSslUrl()
Returns SSL URL to redirect to.
static sslOn()
Returns TRUE if SSLÂ was used to contact FD, whether directly or through a proxy.
static buildAbsoluteUrl(string $path)
Returns absolute URL from relative URL.
static getPageURL($queryString=FALSE)
Returns current page URL.