There are two different issues you are dealing with Susan; that of mis-configured servers with MODx 0.9.5, such as Network Solutions after this upgrade, and that of a change to the auto-configuration code in 0.9.6 release candidates. The 0.9.6 changes PHP_SELF to SCRIPT_NAME, which is a separate problem. IMO, this should go back to PHP_SELF, and remain auto-configured unless a user overrides those settings to avoid server configuration issues (i.e. where you do not have control over the PHP configuration yourself).
I have been thinking that it might be better to have those values calculated at install time and verified by the installer, then written to the database or the config file. This auto-configuration seems to be having problems lately.
’PHP_SELF’
The filename of the currently executing script, relative to the document root. For instance, $_SERVER[’PHP_SELF’] in a script at the address http://example.com/test.php/foo.bar would be /test.php/foo.bar. The __FILE__ constant contains the full path and filename of the current (i.e. included) file.
Warning:
$_SERVER[’PHP_SELF’] and $_SERVER[’SCRIPT_NAME’] may not always be set correctly.
Some web hosts implement php as a CGI in such a way that they can turn it on or off for each virtual domain. Several $_SERVER and $_ENV variable values may be incorrect for documents in subdirectory sub-domains of these virtual domains.
Personally, I’d go with the $_server global and make sure your directives are correct.
$_ENV[’SCRIPT_URL’]work compared to
$_SERVER[’SCRIPT_URL’]...if at all?
The $_env superglobal variables are imported into PHP’s global namespace from the environment under which the PHP parser is running. Many are provided by the shell under which PHP is running and different systems are likely running different kinds of shells, a definitive list is impossible. The PHP manual advises to see your shell’s documentation for a list of defined environment variables.
The entries in the $_server array are created by the webserver.
Personally, I’d go with the $_server global and make sure your directives are correct.
// automatically assign base_path and base_url
if (empty ($base_path) || empty ($base_url) || $_REQUEST['base_path'] || $_REQUEST['base_url']) {
// assign base_path
$base_path= realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..') . DIRECTORY_SEPARATOR;
$base_path= str_replace('\\', '/', $base_path);
if ($base_path{strlen($base_path) - 1} != '/') $base_path .= '/';
// strip appended paths
$base_url= !empty ($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : $_SERVER['REQUEST_URI'];
$base_url= str_replace('\\', '/', $base_url);
$truncate= strpos($base_url, !empty ($_SERVER['SCRIPT_FILENAME']) ? basename($_SERVER['SCRIPT_FILENAME']) : '.php');
if ($truncate !== false)
$base_url= substr($base_url, 0, $truncate);
// walk trough url until we reach our base directory
$base_url_tokens= explode('/', $base_url);
while (count($base_url_tokens) > 0) {
$base_url= implode('/', $base_url_tokens);
if (preg_match('/' . preg_quote($base_url, '/') . '[\/|]$/', $base_path))
break;
array_pop($base_url_tokens);
}
if ($base_url{strlen($base_url) - 1} != '/') $base_url .= '/';
// assign site_url
$site_url= ((isset ($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on') || $_SERVER['SERVER_PORT'] == $https_port) ? 'https://' : 'http://';
$site_url .= $_SERVER['HTTP_HOST'];
if ($_SERVER['SERVER_PORT'] != 80)
$site_url= str_replace(':' . $_SERVER['SERVER_PORT'], '', $site_url); // remove port from HTTP_HOST
$site_url .= ($_SERVER['SERVER_PORT'] == 80 || (isset ($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on') || $_SERVER['SERVER_PORT'] == $https_port) ? '' : ':' . $_SERVER['SERVER_PORT'];
$site_url .= $base_url;
}