<?php
// Anti-Cache Security
header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
use MedBrief\MSR\Kernel;
use Symfony\Component\ErrorHandler\Debug;
use Symfony\Component\HttpFoundation\Request;
require dirname(__DIR__) . '/config/bootstrap.php';
// Force HTTPS on remote dev environments only. A .env.local update is required.
if ($_ENV['APP_ENV'] === 'dev' && $_ENV['DEV_HOST'] === 'remote') {
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
$_SERVER['HTTPS'] = 'on';
$_SERVER['SERVER_PORT'] = 443;
}
}
// Redirect search engine referred traffic to https://ssl.medbrief.co.uk
if (strtolower($_ENV['APP_ENV']) !== 'prod' && !empty($_SERVER['HTTP_REFERER'])) {
// Array of search engine referrers
$redirectReferrersRegex = [
'google',
'bing',
'yahoo',
'duckduckgo',
'ecosia\.org',
'startpage\.com',
'yandex',
'search\.brave\.com',
'ask\.com',
'lycos\.com',
'archive\.org',
'dogpile',
'aol\.com',
];
// Build redirect URL
$redirectURL = 'https://ssl.medbrief.co.uk';
if (!empty($_SERVER['REQUEST_URI'])) {
$redirectURL .= $_SERVER['REQUEST_URI'];
} else {
$redirectURL .= '/login';
}
// Search haystack for each referrer, when referrer found redirect
foreach ($redirectReferrersRegex as $referrer) {
if (preg_match('/' . $referrer . '/i', $_SERVER['HTTP_REFERER'])) {
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $redirectURL);
exit();
}
}
}
// We have chosen to continue using our custom code instead of adopting the changes
// introduced by the composer symfony/framework-bundle recipe update.
// This decision was made to preserve our customizations to the Request and Response objects.
// For reference: introduced by recipe update
// use App\Kernel;
// require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
// return function (array $context) {
// return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
// };
require dirname(__DIR__) . '/config/bootstrap.php';
if ($_SERVER['APP_DEBUG']) {
umask(0000);
Debug::enable();
}
if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? false) {
Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_FOR | Request::HEADER_X_FORWARDED_PORT | Request::HEADER_X_FORWARDED_PROTO);
}
if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? false) {
Request::setTrustedHosts([$trustedHosts]);
}
$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);