Check if page works using SSL in PHP
I need to check if a page works using SSL connection. I know how to check $_SERVER['HTTPS'] == 'on开发者_StackOverflow中文版'. Is this a good way of doing it, or should I use other logic?
Sorry for my english. Thanks.
$_SERVER['HTTPS'] may contain values other than 'on' or it may not be set at all. The manual says it'll be set to a "non empty" value if SSL is used, but on IIS it may be set to 'off'. So, use:
if (empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == 'off') {
// I feel insecure...
} else {
// SSL, yay!
}
On checking the documentation I figured that isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != "off" should be enough to detect if you are using https://, not just $_SERVER['HTTPS"] == "on".
Apparently using ISAPI with IIS the value is, confusingly, set to $_SERVER['HTTPS'], and so an empty() or isset() check alone with not suffice.
加载中,请稍侯......
精彩评论