Dave's Brain

Browse - 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 = safeAccess($_SERVER, 'REQUEST_SCHEME'); $host = safeAccess($_SERVER, 'HTTP_HOST'); $uri = safeAccess($_SERVER, 'REQUEST_URI'); return "$scheme://$host$uri"; }

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.