The PATH_TRANSLATED blues

Wondering if anyone can provide some help / tips for a problem we’ve encountered in WACT. Can imagine other people are having the same problem.

Basically we need a way to determine that path of the script where execution began from within WACT.

Typically when using WACT you’d begin a script like;


// myscript.php
require_once '/path/to/wact/common.inc.php';

// etc...
?>

Code within WACT then needs to be able to determine where myscript.php is located in the filesystem, so that a users templates, for example, can be located relative to myscript.php’s path.

This may seem like a simple problem to solve, by simply using;


$myscript_path = dirname($_SERVER['SCRIPT_FILENAME']);

Unfortunately this only works on some PHP configurations – when PHP is used as a CGI executable (and probably the same for the CLI variant) contains the path to the PHP executable, not the PHP script where execution began.

An alternative option which seemed to look good for a short time was;


$myscript_path = dirname($_SERVER['PATH_TRANSLATED']);

Looking at the PHP bugs list though, there seem to have been issues with this variable, relating to the Apache version being used. Worse news is it’s been completely dropped from PHP5, mentioned here.

Any other ideas for how to reliably determine the path of the script where execution began? Beginning to wonder if PHP needs a predefined constant such as __MAIN__ which handles this independent of PHP install.

Jeff highlights the problem in more detail here.

Replay

Category: programming Time: 2004-06-08 Views: 1
Tags:

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.204 (s). 12 q(s)