If my URL is http://www.server.com/myapp/stuff/to/see
and my directory structure on disk is htdocs/myapp/*
, how can I extract the /myapp
When you access a page using http://www.server.com/myapp/stuff/to/see
, and your webserver's document root is at /something/htdocs/
, then the current local
path is /something/htdocs/myapp/stuff/to/see
.
There is no definite solution to get /something/htdocs/myapp/
as a result now, because there is no clear definition which path you should get. When you have some rule for that, tell us, and we might be able to come up with something, but without computation, the only paths you can see are:
http://www.server.com/myapp/stuff/to/see
$_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']
/something/htdocs/myapp/stuff/to/see/index.php
$_SERVER['SCRIPT_FILENAME']
/something/htdocs/
$_SERVER['DOCUMENT_ROOT']
/myapp/stuff/to/see
$_SERVER['REQUEST_URI']
/myapp/stuff/to/see/index.php
$_SERVER['SCRIPT_NAME']
and $_SERVER['PHP_SELF']