Par exemple, phpinfo affichera :
Sur un serveur Apache sous Windows en http://
_SERVER["HTTPS"] !!!_NOT_SET_!!! _SERVER["SERVER_PORT"] 80 _SERVER["REQUEST_SCHEME"] http
Et un serveur Apache sous Linux en https//
_SERVER["HTTPS"] on _SERVER["SERVER_PORT"] 443 _SERVER["REQUEST_SCHEME"] !!!_NOT_SET_!!!
Donc selon ce qui se dit :
il est conseillé de vérifier au moins la présence $_SERVER\'HTTPS\', par exemples :
// vérification de base
if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
// SSL connection
}
// ou vérification supplémentaire des ports (qui peuvent être différents de 443...)
function is_ssl() {
if ( isset($_SERVER['HTTPS']) ) {
if ( 'on' == strtolower($_SERVER['HTTPS']) )
return true;
if ( '1' == $_SERVER['HTTPS'] )
return true;
} elseif ( isset($_SERVER['SERVER_PORT']) && ( '443' == $_SERVER['SERVER_PORT'] ) ) {
return true;
}
return false;
}