PHP获取完整的服务器名称,包括端口号和协议 [英] PHP getting full server name including port number and protocol
本文介绍了PHP获取完整的服务器名称,包括端口号和协议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在PHP中,是否存在可靠以及获取这些内容的好方法:
In PHP, is there a reliable and good way of getting these things:
协议:即http或https 伺服器名称:例如本地主机 端口号:例如8080
Protocol: i.e. http or https Servername: e.g. localhost Portnumber: e.g. 8080
我可以使用$_SERVER['SERVER_NAME']
获取服务器名称.
I can get the server name using $_SERVER['SERVER_NAME']
.
我可以获取协议,但是我认为它并不完美:
I can kind of get the protocol but I don't think it's perfect:
if(strtolower(substr($_SERVER["SERVER_PROTOCOL"],0,5))=='https') {
return "https";
}
else {
return "http";
}
我不知道如何获取端口号.我使用的端口号不是80.它们是8080和8888.
I don't know how to get the port number though. The port numbers I am using are not 80.. they are 8080 and 8888.
谢谢.
推荐答案
看看文档.
你想$_SERVER['SERVER_PORT']
我想.
这篇关于PHP获取完整的服务器名称,包括端口号和协议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文