PHP getting full server name including port number and protocol
- by vivid-colours
In PHP, is there a reliable and good way of getting these things:
Protocol: i.e. http or https
Servername: e.g. localhost
Portnumber: e.g. 8080
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";
}
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.
Thank you.