/**
* 功能 : 获取域名
* @return
*/
function serverName() {
if(isset($_SERVER['HTTP_HOST'])){
if(stripos($_SERVER['HTTP_HOST'],']')) {
$thisserver_names=explode(']',$_SERVER['HTTP_HOST']);
$name=$thisserver_names[0].']';
}else {
$thisserver_names=explode(':',$_SERVER['HTTP_HOST']);
$name=$thisserver_names[0];
}
}else {
if(!isset($_SERVER['SERVER_NAME'])) {$_SERVER['SERVER_NAME']='';}
$name=$_SERVER['SERVER_NAME'];
}
Return strtolower($name);
}
/**
* 功能 : 获取端口号
* @return
*/
function serverPort($colon=true) {
if(isset($_SERVER['HTTP_HOST'])){
if(stripos($_SERVER['HTTP_HOST'],']')) {
$thisserver_port=explode(']:',$_SERVER['HTTP_HOST']);
}else {
$thisserver_port=explode(':',$_SERVER['HTTP_HOST']);
}
if(isset($thisserver_port[1]) && is_numeric($thisserver_port[1])) {
$port=$thisserver_port[1];
}else {
$port='80';
}
}elseif(isset($_SERVER['SERVER_PORT']) && is_numeric($_SERVER['SERVER_PORT'])) {
$port=$_SERVER['SERVER_PORT'];
}else {
$port='80';
}
if($port=='80') {
Return '';
}elseif($colon) {
Return ':'.$port;
}else{
Return $port;
}
}
网友评论