mon site 33333

This commit is contained in:
Flatlogic Bot 2026-05-02 10:15:56 +00:00
parent 0f59065612
commit 95ba206594

View File

@ -25,6 +25,78 @@ function site_asset_version(): string
return $version;
}
function site_request_scheme(): string
{
$cfVisitor = (string) ($_SERVER['HTTP_CF_VISITOR'] ?? '');
if ($cfVisitor !== '') {
$decoded = json_decode($cfVisitor, true);
if (is_array($decoded) && isset($decoded['scheme']) && in_array($decoded['scheme'], ['http', 'https'], true)) {
return $decoded['scheme'];
}
}
$forwardedProto = (string) ($_SERVER['HTTP_X_FORWARDED_PROTO'] ?? '');
if ($forwardedProto !== '') {
$proto = strtolower(trim(explode(',', $forwardedProto)[0]));
if (in_array($proto, ['http', 'https'], true)) {
return $proto;
}
}
$requestScheme = strtolower((string) ($_SERVER['REQUEST_SCHEME'] ?? ''));
if (in_array($requestScheme, ['http', 'https'], true)) {
return $requestScheme;
}
return (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
}
function site_request_host(): string
{
$host = strtolower(trim((string) ($_SERVER['HTTP_HOST'] ?? '')));
if ($host === '') {
return 'programmetelecesoir.net';
}
$host = preg_replace('/:\d+$/', '', $host) ?? $host;
return $host !== '' ? $host : 'programmetelecesoir.net';
}
function site_is_local_host(string $host): bool
{
return in_array($host, ['127.0.0.1', 'localhost'], true)
|| str_ends_with($host, '.local');
}
function site_enforce_public_url(): void
{
if (PHP_SAPI === 'cli') {
return;
}
$canonicalDomain = 'programmetelecesoir.net';
$host = site_request_host();
if ($host === '' || site_is_local_host($host)) {
return;
}
$scheme = site_request_scheme();
if ($host === $canonicalDomain && $scheme === 'https') {
return;
}
$requestUri = (string) ($_SERVER['REQUEST_URI'] ?? '/');
if ($requestUri === '') {
$requestUri = '/';
}
header('Vary: Host, X-Forwarded-Proto, CF-Visitor', false);
header('Location: https://' . $canonicalDomain . $requestUri, true, 301);
exit;
}
site_enforce_public_url();
function site_settings(): array
{
static $settings = null;
@ -32,9 +104,9 @@ function site_settings(): array
return $settings;
}
$scheme = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
$scheme = site_request_scheme();
$canonicalDomain = 'programmetelecesoir.net';
$host = $_SERVER['HTTP_HOST'] ?? $canonicalDomain;
$host = site_request_host();
$projectName = (string) ($_SERVER['PROJECT_NAME'] ?? '');
if ($projectName === '' || strcasecmp($projectName, 'programmetelecesoir.fr') === 0) {
$projectName = $canonicalDomain;