2024-04-30 11:31:06 +02:00
|
|
|
<?php
|
|
|
|
namespace Vichan\Functions\Net;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2024-05-11 16:02:15 +02:00
|
|
|
* @param bool $trust_headers. If true, trust the `HTTP_X_FORWARDED_PROTO` header to check if the connection is HTTPS.
|
2024-04-30 11:31:06 +02:00
|
|
|
* @return bool Returns if the client-server connection is an encrypted one (HTTPS).
|
|
|
|
*/
|
2024-05-11 16:02:15 +02:00
|
|
|
function is_connection_secure(bool $trust_headers): bool {
|
|
|
|
if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') {
|
|
|
|
return true;
|
|
|
|
} elseif ($trust_headers && isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
|
|
|
|
return true;
|
|
|
|
}
|
2024-05-11 13:42:45 +02:00
|
|
|
return false;
|
2024-04-30 11:31:06 +02:00
|
|
|
}
|