getting current url

scm0sml
scm0sml used Ask the Experts™
on
i have a website.

i also then have a carbon copy sandbox test version of the site.

i am using google analytics.

is there anyway of getting the current url so i can see if /sanbox/ is in the url, so i can leave out the analytics code that goes at the bottom of the page?

this would allow me to copy and paste files rather than having to make the changes to both live and test code(to avoid test site vewings amending my google stats)

any ideas how i can get the url i am currently on?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Sure:

$currentURL = $_SERVER['PHP_SELF'];

and then use preg_match() or strstr() to look for /sandbox/

Hope that helps?
Top Expert 2004
Commented:
Through the $_SERVER superglobal would be the easiest way:

http://www.php.net/manual/en/reserved.variables.php#reserved.variables.server

Author

Commented:
ok so for e.g if i have a url:
www.someaddress.co.uk/sandbox/index.php

using the above i get:
sandbox/index.php which will allow me to do the above but is there a way of getting the whole url, i.e www.someaddress..........index.php

as this would also allow me to tell if i was running locally or uploaded to allow local code to not affect stats too?
Sure:

$myUrl = $_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];

Author

Commented:
perfect, cheers guys.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial