same here:
I've tracked it back to: cpg_get_webroot_path()
I've moved its code to a standalone page so I could comment it and see whats happening:
<html>
<head>
<title>Testing</title>
</head>
<body>
<?php
//global $PHP_SELF;
// get the webroot folder out of a given PHP_SELF of any coppermine page
// what we have: we can say for sure where we are right now: $PHP_SELF (if the server doesn't even have it, there will be problems everywhere anyway)
echo "PHP_SELF: $PHP_SELF <br>";
// let's make those into an array:
$path_from_serverroot[] = $_SERVER["SCRIPT_FILENAME"];
if (isset($_SERVER["PATH_TRANSLATED"])) {
$path_from_serverroot[] = $_SERVER["PATH_TRANSLATED"];
}
$path_from_serverroot[] = $HTTP_SERVER_VARS["SCRIPT_FILENAME"];
$path_from_serverroot[] = $HTTP_SERVER_VARS["PATH_TRANSLATED"];
// we should be able to tell the current script's filename by removing everything before and including the last slash in $PHP_SELF
$filename = ltrim(strrchr($_SERVER['PHP_SELF'], '/'), '/');
echo "path_from_serverroot : ";
echo "<pre>";
print_r($path_from_serverroot);
echo "</pre>";
echo "filename: $filename <br>";
// let's eliminate all those vars that don't contain the filename (and replace the funny notation from windows machines)
foreach($path_from_serverroot as $key) {
$key = str_replace('\\\\', '/', $key); // replace the windows notation
if(strstr($key, $filename) != FALSE) { // eliminate all that don't contain the filename
$path_from_serverroot2[] = $key;
}
}
echo "path_from_serverroot2 : ";
echo "<pre>";
print_r($path_from_serverroot2);
echo "</pre>";
// remove double entries in the array
$path_from_serverroot3 = array_unique($path_from_serverroot2);
echo "path_from_serverroot3 : ";
echo "<pre>";
print_r($path_from_serverroot3);
echo "</pre>";
// in the best of all worlds, the array is not empty
if (is_array($path_from_serverroot3)) {
$counter = 0;
foreach($path_from_serverroot3 as $key) {
// easiest possible solution: $PHP_SELF is contained in the array - if yes, we're lucky (in fact we could have done this before, but I was going to leave room for other checks to be inserted before this one)
if(strstr($key, $_SERVER['PHP_SELF']) != FALSE) { // eliminate all that don't contain $PHP_SELF
$path_from_serverroot4[] = $key;
$counter++;
}
}
} else {
// we're f***ed: the array is empty, there's no server var we could actually use
echo "It thinks there's no server var we could use <br>";
$return = '';
}
if ($counter == 1) { //we have only one entry left - we're happy
$return = $path_from_serverroot4[0];
echo "path_from_serverroot4 : ";
echo "<pre>";
print_r($path_from_serverroot4);
echo "</pre>";
} elseif ($counter == 0) { // we're f***ed: the array is empty, there's no server var we could actually use
echo "Second spot it thinks theres no server var <br>";
$return = '';
} else { // there is more than one entry, and they differ. For now, let's use the first one. Maybe we could do some advanced checking later
$return = $path_from_serverroot4[0];
echo "path_from_serverroot4 : ";
echo "<pre>";
print_r($path_from_serverroot4);
echo "</pre>";
echo "thinks there is more than one entry and they differ <br>";
}
// strip the content from $PHP_SELF from the $return var and we should (hopefully) have the absolute path to the webroot
$return = str_replace($_SERVER['PHP_SELF'], '', $return);
echo "Supposedly absolute path to the webroot: $return <br>";
// the return var should at least contain a slash - if it doesn't, add it (although this is more or less wishfull thinking)
if ($return == '') {
$return = '/';
}
echo "What is finally returned: $return <br>";
?>
</body></html>
this is what I'm getting as output:
Notice: Undefined variable: PHP_SELF in c:\inetpub\wwwroot\webroot.php on line 12
PHP_SELF:
Notice: Undefined index: SCRIPT_FILENAME in c:\inetpub\wwwroot\webroot.php on line 15
Notice: Undefined index: SCRIPT_FILENAME in c:\inetpub\wwwroot\webroot.php on line 19
path_from_serverroot :
Array
(
[0] =>
[1] => c:\inetpub\wwwroot\webroot.php
[2] =>
[3] => c:\inetpub\wwwroot\webroot.php
)
filename: webroot.php
path_from_serverroot2 :
Array
(
[0] => c:\inetpub\wwwroot\webroot.php
[1] => c:\inetpub\wwwroot\webroot.php
)
path_from_serverroot3 :
Array
(
[0] => c:\inetpub\wwwroot\webroot.php
)
Second spot it thinks theres no server var
Supposedly absolute path to the webroot:
What is finally returned: /