Programming Tips - How can I get my URL in php?

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