Refactor configuration loading: Updated multiple public PHP files to require a new bootstrap file for configuration management. Adjusted paths for product configuration to enhance maintainability and consistency across the application.

This commit is contained in:
smueller
2026-05-22 13:58:30 +02:00
parent ec8686761c
commit 96a5977283
19 changed files with 151 additions and 31 deletions

View File

@@ -0,0 +1,68 @@
<?php
/**
* HexaHost.de zentrale Domain- und Umgebungskonfiguration
*/
define('SITE_DOMAIN_PRODUCTION', 'hexahost.de');
define('SITE_DOMAIN_DEVELOPMENT', 'dev.hexahost.de');
/**
* Aktuellen HTTP-Host (ohne Port) ermitteln
*/
function getSiteHost(): string
{
$host = $_SERVER['HTTP_HOST'] ?? SITE_DOMAIN_PRODUCTION;
$host = strtolower($host);
if (str_contains($host, ':')) {
$host = explode(':', $host, 2)[0];
}
return $host;
}
/**
* true, wenn die Seite unter der Dev-Domain läuft
*/
function isDevelopmentSite(): bool
{
return getSiteHost() === SITE_DOMAIN_DEVELOPMENT;
}
/**
* Basis-URL der aktuellen Anfrage (Schema + Host)
*/
function getSiteBaseUrl(): string
{
$https = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off')
|| (isset($_SERVER['SERVER_PORT']) && (int) $_SERVER['SERVER_PORT'] === 443);
$scheme = $https ? 'https' : 'http';
return $scheme . '://' . getSiteHost();
}
/**
* Erlaubte CORS-Origins für AJAX (Kontaktformular)
*
* @return list<string>
*/
function getAllowedOrigins(): array
{
return [
'https://' . SITE_DOMAIN_PRODUCTION,
'https://www.' . SITE_DOMAIN_PRODUCTION,
'https://' . SITE_DOMAIN_DEVELOPMENT,
'http://localhost',
'http://127.0.0.1',
'http://localhost:8000',
];
}
/**
* Kanonische Basis-URL für SEO (Produktion immer hexahost.de)
*/
function getCanonicalBaseUrl(): string
{
return 'https://' . SITE_DOMAIN_PRODUCTION;
}

View File

@@ -3,6 +3,12 @@
* Helper functions for HexaHost.de
*/
$configDir = defined('HEXAHOST_CONFIG_DIR')
? HEXAHOST_CONFIG_DIR
: __DIR__ . '/../config';
require_once $configDir . '/site-config.php';
// Sichere Session-Konfiguration
if (session_status() === PHP_SESSION_NONE) {
// Session-Cookie-Sicherheit
@@ -51,6 +57,11 @@ function includeHeader($title = '', $description = '', $page = '', $scripts = []
$current_page = $page;
$additional_scripts = $scripts;
if (!isset($canonical_url)) {
$requestPath = parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH) ?: '/';
$canonical_url = rtrim(getCanonicalBaseUrl(), '/') . $requestPath;
}
include __DIR__ . '/header.php';
}

View File

@@ -1,5 +1,8 @@
<!DOCTYPE html>
<?php require_once __DIR__ . '/../config/products-config.php'; ?>
<?php
$configDir = defined('HEXAHOST_CONFIG_DIR') ? HEXAHOST_CONFIG_DIR : __DIR__ . '/../config';
require_once $configDir . '/products-config.php';
?>
<html lang="de">
<head>
<meta charset="UTF-8">