Replace $_SERVER['SERVER_NAME'] with url()

Fixes issue where $_SERVER['SERVER_NAME'] returns a value that doesn't match $GLOBALS['base_url'], thus generating invalid public-facing URLs.

$GLOBALS['base_url'] is derived from $_SERVER['HTTP_HOST'], which is the contents of the Host: HTTP header from the current page request. $_SERVER['SERVER_NAME'] is the name of the server host under which the current script is executing. For VirtualHost environments, $_SERVER['HTTP_HOST'] is going to be a more reliable source to generate public-facing URLs.

--

My previous commit didn't actually work because $GLOBALS['base_url'] includes the protocol, which we are also prefixing here.

However, if we reduce this whole block of code down, we're essentially reproducing the output of `url()`, a core function.