I can't seem to find a super-global for this. Basically, if a PHP file is executed on, say, http://www.example.com/services/page.php
, I would like to retrieve http://example.com/services
. How do I achieve this?
views:
91answers:
3
+4
A:
You can abuse dirname
:
<p>
<?php echo $_SERVER["HTTP_HOST"] . dirname($_SERVER["REQUEST_URI"]) ?>
</p>
Sinan Ünür
2009-07-23 16:24:47
+5
A:
Take a look at $_SERVER['HTTP_HOST']
and $_SERVER['REQUEST_URI']
. HTTP_HOST
would contain the host name the resource was requested from an REQUEST_URI
URI path and query that was requested.
Gumbo
2009-07-23 16:25:02
A:
Jeff Busby
2009-07-23 17:21:54