= 2 && ($value[0] === '"' || $value[0] === "'") && substr($value, -1) === $value[0]) $value = substr($value, 1, -1); $values[$name] = $value; } } } return array_key_exists($key, $values) ? $values[$key] : $default; } /* * The address of the site comes from SITE_URL, never from the Host * header, which the browser controls. site_url() gives the scheme, host * and port (for example "https://xxx.org.za"), and site_host() gives the * host. Both are empty if SITE_URL has no host. */ function site_url_parts() { $site = parse_url(trim((string)config('SITE_URL', ''))); return is_array($site) && !empty($site['host']) ? $site : array(); } function site_host() { return site_url_parts()['host'] ?? ''; } function site_url($scheme = NULL) { $site = site_url_parts(); if (!$site) return ''; $port = isset($site['port']) ? ':' . $site['port'] : ''; return ($scheme ?? $site['scheme'] ?? 'https') . '://' . $site['host'] . $port; } // An address at the site's host, such as "editor@xxx.org.za" function site_email($name) { return $name . '@' . site_host(); } // The cookie domain: the site's host and its subdomains function cookie_domain() { return site_host() === '' ? '' : '.' . site_host(); } /* * Send a plain HTTP request to the same page over HTTPS, and stop. * Without SITE_URL, the page refuses plain HTTP. */ function require_https() { if (isset($_SERVER['HTTPS'])) return; if (site_url() === '') { http_response_code(403); echo "This page needs HTTPS.\n"; } else { header('Location: ' . site_url('https') . $_SERVER['REQUEST_URI']); } exit; } // Always log PHP errors; show them only if DISPLAY_ERRORS is set (for development) ini_set('log_errors', '1'); ini_set('display_errors', (string)config('DISPLAY_ERRORS', '0')); ?>