PHP getting full server name including port number and protocol
Posted
by
vivid-colours
on Stack Overflow
See other posts from Stack Overflow
or by vivid-colours
Published on 2011-09-15T13:04:15Z
Indexed on
2012/04/07
11:29 UTC
Read the original article
Hit count: 193
php
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.
© Stack Overflow or respective owner