php
if (isset($_SERVER['SERVER_PORT'])) { $port = ':' . $_SERVER['SERVER_PORT']; if ((':80' == $port && 'http://' == $protocol) || (':443' == $port && ' https://' == $protocol)) { $port = ''; } }
其中
if ((':80' == $port && 'http://' == $protocol) || (':443' == $port && 'https://' == $protocol)) { $port = ''; }
這段代碼的意思作用是什嗎? 如果條件成立,為什麼要把$port 設定為空白?
整個函數的代碼:
function get_domain() { /* 協議 */ $protocol = $this->http(); /* 網域名稱或IP地址 */ if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) { $host = $_SERVER['HTTP_X_FORWARDED_HOST']; } elseif (isset($_SERVER['HTTP_HOST'])) { $host = $_SERVER['HTTP_HOST']; } else { /* 連接埠 */ if (isset($_SERVER['SERVER_PORT'])) { $port = ':' . $_SERVER['SERVER_PORT']; if ((':80' == $port && 'http://' == $protocol) || (':443' == $port && 'https://' == $protocol)) { $port = ''; } } else { $port = ''; } if (isset($_SERVER['SERVER_NAME'])) { $host = $_SERVER['SERVER_NAME'] . $port; } elseif (isset($_SERVER['SERVER_ADDR'])) { $host = $_SERVER['SERVER_ADDR'] . $port; } } return $protocol . $host; }