开发者

php - methods for determining if traffic is through https or http

开发者 https://www.devze.com 2023-02-18 10:39 出处:网络
I need a simple function to decide if the it\'s using https or http. I was thinking - is there a way for php to access the port #? So if it\'s 443 I know 开发者_JS百科it\'s secure, and if it\'s 80 I k

I need a simple function to decide if the it's using https or http. I was thinking - is there a way for php to access the port #? So if it's 443 I know 开发者_JS百科it's secure, and if it's 80 I know it's normal.

What other ways are there of determining this?


<?php 
if($_SERVER['HTTPS']){ 
  //secure 
}else{ 
  // not secure
} 
?> 

However some servers don't set HTTPS, so in the worst case:

<?php
if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) {
  // secure
}
?>
0

精彩评论

暂无评论...
验证码 换一张
取 消