Home >Backend Development >PHP Tutorial >php里如何检测当前是不是正在使用https协议?

php里如何检测当前是不是正在使用https协议?

WBOY
WBOYOriginal
2016-06-06 20:37:291163browse

看到很多程序用下面这段代码

<code>php</code><code>if (strtoupper($_SERVER['HTTPS']) == 'ON') {
    ...
}
</code>

但是很多服务器压根就没发送HTTPS这个头给php-fpm啊?到底应该怎么做才准呢?

回复内容:

看到很多程序用下面这段代码

<code>php</code><code>if (strtoupper($_SERVER['HTTPS']) == 'ON') {
    ...
}
</code>

但是很多服务器压根就没发送HTTPS这个头给php-fpm啊?到底应该怎么做才准呢?

<code>php</code><code>function is_HTTPS(){  
    if(!isset($_SERVER['HTTPS']))  return FALSE;  
    if($_SERVER['HTTPS'] === 1){  //Apache  
        return TRUE;  
    }elseif($_SERVER['HTTPS'] === 'on'){ //IIS  
        return TRUE;  
    }elseif($_SERVER['SERVER_PORT'] == 443){ //其他  
        return TRUE;  
    }  
    return FALSE;  
}  
</code>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn