getting current url

scm0sml used Ask the Experts™
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?
Watch Question

Do more with

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

$currentURL = $_SERVER['PHP_SELF'];

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

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


ok so for e.g if i have a url:

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?



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