Replace $_SERVER['SERVER_NAME'] with $GLOBALS['base_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.