|
Posted by Steve on 01/03/08 15:13
> mmmm, path dependency...
>
> So, what do you recommend instead, then, that wouldn't use
> document_root? Saying 'switch hosts' doesn't help much, as it's not
> gonna happen.
that's about all you're going to get from jerry. :)
i'll repost this:
<?
$parsedUri = dirname($_SERVER['PHP_SELF']);
$parsedUri .= substr($parsedUri, -1) != '/' ? '/' : '';
$relativeUri = str_replace('/', '', $parsedUri);
$relativePath = strlen($parsedUri) - strlen($relativeUri) - 1;
if ($relativePath < 0){ $relativePath = 0; }
$relativePath = str_repeat('../', $relativePath);
if (!$relativePath){ $relativePath = './'; }
?>
name that whatever you will...say, relative.path.php, for instance. put that
script in your php include_path. from there, it doesn't matter where your
parent script is run. you get document_root in relative terms regardless of
what your server's configuration is. to implement this, just do this at the
top of your parent script:
<?
require_once 'relative.path.php';
include_once $relativePath . 'name of other script to include here';
// rest of code
?>
hth,
me
Navigation:
[Reply to this message]
|