RE: [PHP] Relative Url
| From: | Rick Fletcher | Date: | Thu, 01 Apr 2004 18:38:30 +0000 |
| Subject: | RE: [PHP] Relative Url | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-182055@lists.php.net to get a copy of this message | ||
> Is there anyway that i can get a url relative to my server
> for a script that is being run??
>
> The script is being included in mulitple files and
> $_SERVER['SCRIPT_NAME'] just gives me the name of the file
> that is including the other scripts.
> Also $_SERVER['SCRIPT_FILENAME'] is returning nothing.
I'm not completely sure I know what you're after. If you're looking to get
the http path to an included file, this should work:
<?php
$http_path = "http://" . $_SERVER['SERVER_NAME'] .
str_replace( $_SERVER['DOCUMENT_ROOT'], "", __FILE__ );
?>
If you're in windows I don't think the replace would work, because the
docroot's slashes go one way and the __FILE__ slashes go the other. You'd
use something like strtr( __FILE__, "\\", "/" ) before the replacement to
fix that.
Cheers,
Rick