35 lines
1.3 KiB
PHP
35 lines
1.3 KiB
PHP
<?php
|
|
/**
|
|
* EduBox reverse proxy normalisation for PrestaShop 9 running behind the
|
|
* EduBox dynamic-public-domain resolver.
|
|
*
|
|
* The official PrestaShop 9 + PHP 8.5 + Apache image has a bug where
|
|
* X-Forwarded-* headers are exposed to PHP as arrays whose value is the
|
|
* header name. getenv() returns the correct string, so we use it to
|
|
* reconstruct $_SERVER entries used by Tools::getHttpHost/ShopDomainSSL.
|
|
*/
|
|
|
|
if ($val = getenv('HTTP_X_FORWARDED_HOST')) {
|
|
$_SERVER['HTTP_X_FORWARDED_HOST'] = $val;
|
|
}
|
|
if ($val = getenv('HTTP_X_FORWARDED_PROTO')) {
|
|
$_SERVER['HTTP_X_FORWARDED_PROTO'] = $val;
|
|
}
|
|
|
|
// Apache/PHP 8.5 sometimes corrupts HTTP_HOST into an array; fall back safely.
|
|
if (!empty($_SERVER['HTTP_HOST']) && is_array($_SERVER['HTTP_HOST'])) {
|
|
$_SERVER['HTTP_HOST'] = !empty($_SERVER['SERVER_NAME']) && !is_array($_SERVER['SERVER_NAME'])
|
|
? $_SERVER['SERVER_NAME']
|
|
: (getenv('HTTP_X_FORWARDED_HOST') ?: 'localhost');
|
|
}
|
|
|
|
if (!empty($_SERVER['HTTPS']) && is_array($_SERVER['HTTPS'])) {
|
|
$_SERVER['HTTPS'] = 'off';
|
|
}
|
|
|
|
// Tell Symfony to trust the EduBox resolver so $request->isSecure() and
|
|
// $request->getHost() honour X-Forwarded-* headers.
|
|
putenv('PS_TRUSTED_PROXIES=127.0.0.1,REMOTE_ADDR');
|
|
$_SERVER['PS_TRUSTED_PROXIES'] = '127.0.0.1,REMOTE_ADDR';
|
|
$_ENV['PS_TRUSTED_PROXIES'] = '127.0.0.1,REMOTE_ADDR';
|