public/index.php line 87

Open in your IDE?
  1. <?php
  2. // Anti-Cache Security
  3. header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
  4. header('Cache-Control: post-check=0, pre-check=0', false);
  5. header('Pragma: no-cache');
  6. use MedBrief\MSR\Kernel;
  7. use Symfony\Component\ErrorHandler\Debug;
  8. use Symfony\Component\HttpFoundation\Request;
  9. require dirname(__DIR__) . '/config/bootstrap.php';
  10. // Force HTTPS on remote dev environments only. A .env.local update is required.
  11. if ($_ENV['APP_ENV'] === 'dev' && $_ENV['DEV_HOST'] === 'remote') {
  12. if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
  13. $_SERVER['HTTPS'] = 'on';
  14. $_SERVER['SERVER_PORT'] = 443;
  15. }
  16. }
  17. // Redirect search engine referred traffic to https://ssl.medbrief.co.uk
  18. if (strtolower($_ENV['APP_ENV']) !== 'prod' && !empty($_SERVER['HTTP_REFERER'])) {
  19. // Array of search engine referrers
  20. $redirectReferrersRegex = [
  21. 'google',
  22. 'bing',
  23. 'yahoo',
  24. 'duckduckgo',
  25. 'ecosia\.org',
  26. 'startpage\.com',
  27. 'yandex',
  28. 'search\.brave\.com',
  29. 'ask\.com',
  30. 'lycos\.com',
  31. 'archive\.org',
  32. 'dogpile',
  33. 'aol\.com',
  34. ];
  35. // Build redirect URL
  36. $redirectURL = 'https://ssl.medbrief.co.uk';
  37. if (!empty($_SERVER['REQUEST_URI'])) {
  38. $redirectURL .= $_SERVER['REQUEST_URI'];
  39. } else {
  40. $redirectURL .= '/login';
  41. }
  42. // Search haystack for each referrer, when referrer found redirect
  43. foreach ($redirectReferrersRegex as $referrer) {
  44. if (preg_match('/' . $referrer . '/i', $_SERVER['HTTP_REFERER'])) {
  45. header('HTTP/1.1 301 Moved Permanently');
  46. header('Location: ' . $redirectURL);
  47. exit();
  48. }
  49. }
  50. }
  51. // We have chosen to continue using our custom code instead of adopting the changes
  52. // introduced by the composer symfony/framework-bundle recipe update.
  53. // This decision was made to preserve our customizations to the Request and Response objects.
  54. // For reference: introduced by recipe update
  55. // use App\Kernel;
  56. // require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
  57. // return function (array $context) {
  58. // return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
  59. // };
  60. require dirname(__DIR__) . '/config/bootstrap.php';
  61. if ($_SERVER['APP_DEBUG']) {
  62. umask(0000);
  63. Debug::enable();
  64. }
  65. if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? false) {
  66. Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_FOR | Request::HEADER_X_FORWARDED_PORT | Request::HEADER_X_FORWARDED_PROTO);
  67. }
  68. if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? false) {
  69. Request::setTrustedHosts([$trustedHosts]);
  70. }
  71. $kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
  72. $request = Request::createFromGlobals();
  73. $response = $kernel->handle($request);
  74. $response->send();
  75. $kernel->terminate($request, $response);