if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off'
|| $_SERVER['SERVER_PORT'] == 443) {
// HTTPS
} else {
// HTTP
}
HTTP or HTTPS
Chris Coyier
on
Thank you so much for this… I’ve been trying to do something similar for the last 2 weeks… can’t believe I’ve just found this now!!
Very unstable future because server environment can be switched. Try to use this future:
function detectSSL(): ?bool {
}
.htaccess
SSL schema off
RewriteCond %{HTTPS} off
RewriteRule .* – [E=REQUEST_SCHEME:http]
SSL schema
RewriteCond %{HTTPS} on
RewriteRule .* – [E=REQUEST_SCHEME:https]