PHP getting full server name including port number and protocol
<p>In PHP, is there a <strong>reliable</strong> and good way of getting these things:</p>

<p>Protocol: i.e. http or https
Servername: e.g. localhost
Portnumber: e.g. 8080</p>

<p>I can get the server name using <code>$_SERVER['SERVER_NAME']</code>.</p>

<p>I can kind of get the protocol but I don't think it's perfect: </p>

<pre><code>    if(strtolower(substr($_SERVER["SERVER_PROTOCOL"],0,5))=='https') {
        return "https";
    }
    else {
        return "http";
    }
</code></pre>

<p>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.</p>

<p>Thank you.</p>
