Programming Tips - PHP: see if this a secure connection (ie https)

Date: 2020may1 Updated: 2024sep13 Language: php Q. PHP: see if this a secure connection (ie https) A. Here are some simple functions that can do that:
function isSecure(): bool { return strtolower($_SERVER['HTTPS']) == 'on'; } function getProtocol(): string { return isSecure() ? 'https' : 'http'; }
Example use:
if (isSecure()) { print "Secure connection\n"; } else { print "Non-secure connection\n"; }