检查服务器是否为https不起作用

I'm trying to check if a server has https enabled but it never goes into the if, but in the else statement.

if ($_SERVER['HTTPS'] == "yes") {
    echo "HTTPS";
} else {
     echo "HTTP";
}

what am I doing wrong?

It should read "on", not "yes"

if ($_SERVER['HTTPS'] == "on") {
    echo "HTTPS";
} else {
     echo "HTTP";
}

I would echo the server[https] variable. Depending on the server it may be 'on' not 'yes'.

According to http://php.net/manual/en/reserved.variables.server.php

'HTTPS' Set to a non-empty value if the script was queried through the HTTPS protocol.

But it also adds:

Note: Note that when using ISAPI with IIS, the value will be off if the request was not made through the HTTPS protocol. 

So, I would use a different logic:

<code>
if ( empty( $_SERVER['HTTPS'] ) ) {
    echo 'http:';
}
else if ( $_SERVER['HTTPS'] == 'off' ) {
    echo 'http:';
}
else {
    echo 'https:';
}
</code>

This way it does not matter if it is "on" or "yes". However, I do not have an environment to test this for the https case. http works in my case.