Programming Tips - PHP: get my URL in php

Date: 2016nov26 Language: php Q. PHP: get my URL in php A. Glue together some environment variables like this:
# Helper function function safeAccess(array &$myarray, string $key): string { if (!isset($myarray[$key])) return ''; return $myarray[$key]; } function myUrl(): string { $scheme = getScheme(); # See other page $host = safeAccess($_SERVER, 'HTTP_HOST'); $uri = safeAccess($_SERVER, 'REQUEST_URI'); return "$scheme://$host$uri"; }