HTTP_HOST , SERVER_NAME 区别 php
当端口是80的时候,他们的内容是一样的。
但是当端口不是80的时候,就不一样了。
# HTTP_HOST = SERVER_NAME:SERVER_PORT /** * 获取当前的host */ public static function getSelfHost() { # HTTP_HOST = SERVER_NAME:SERVER_PORT $host = ‘http://‘.$_SERVER[‘HTTP_HOST‘].‘/‘; return $host; } /** * 获取当前的host */ public static function getHttpHost() { if ((int)$_SERVER[‘SERVER_PORT‘] === 80) { $host = ‘http://‘.$_SERVER[‘SERVER_NAME‘].‘/‘; } else { $host = ‘http://‘.$_SERVER[‘SERVER_NAME‘].‘:‘.$_SERVER[‘SERVER_PORT‘].‘/‘; } return $host; }
HTTP_HOST , SERVER_NAME 区别 php
[db:回答]