and pages such as http://<host>/<installation_path>/subfolder1/subfolder2/page.php You have a file called config.php in <installation_path> which is include()d by all pages (in subfolders or not). How to work out <installation_path> without hard-coding it into a config file? <?php // this is config.php, and it is in <installation_path> // it is included by <installation_path>/page.php // it is included by <installation_path>/subfolder/page2.php // etc $_REAL_SCRIPT_DIR = realpath(dirname($_SERVER['SCRIPT_FILENAME'])); // filesystem path of this page's directory (page.php) $_REAL_BASE_DIR = realpath(dirname(__FILE__)); // filesystem path of this file's directory (config.php) $_MY_PATH_PART = substr( $_REAL_SCRIPT_DIR, strlen($_REAL_BASE_DIR)); // just the subfolder part between <installation_path> and the page $INSTALLATION_PATH = $_MY_PATH_PART ? substr( dirname($_SERVER['SCRIPT_NAME']), 0, -strlen($_MY_PATH_PART) ) : dirname($_SERVER['SCRIPT_NAME']) ; // we subtract the subfolder part from the end of <installation_path>, leaving us with just <installation_path> :) ?> todd dot kisov at yahoo dot com 03-Apr-2006 05:11 To convert query string parameter values ($_GET, $_REQUEST), which include escaped Unicode values resulting from applying the javascript "escape" function to a Unicode string (%uNNNN%uNNNN%uNNNN) fast and simple is to use PECL JSON extension: function JavaScript_Unicode_URL_2_Str($js_uni_str) { $res = preg_replace('/%u([[:alnum:]]{4})/', '\\u\1', $js_uni_str); $res = str_replace('"', '\"', $res); // if in str " $res = json_decode('["'.$res.'"]'); // JavaScrip array with string element $res = $res[0]; $res = iconv('UTF-8', ini_get('default_charset'), $res); return $res; } 01-Apr-2006 01:56 I was unable to convince my hosting company to change their installation of PHP and therefore had to find my own way to computer $_SERVER["DOCUMENT_ROOT"]. I eventually settled on the following, which is a combination of earlier notes (with some typos corrected): <?php if ( ! isset($_SERVER['DOCUMENT_ROOT'] ) ) $_SERVER['DOCUMENT_ROOT'] = str_replace( '\\', '/', substr( $_SERVER['SCRIPT_FILENAME'], 0, 0-strlen($_SERVER['PHP_SELF']) ) ); ?> mjs at beebo dot org 30-Mar-2006 05:24 Note that PHP_SELF will not be equal to REQUEST_URI under Apache if mod_rewrite has been used to move one URL to another--PHP_SELF will contain the rewritten address, and REQUEST_URI will contain the URL the user sees in their browser. adam3000 at gmail dot com 16-Mar-2006 02:30 I was trying to find an alternative to $_SERVER['REQUEST_URI'] for a Windows NT set up and the ones below didn't really work for me so here's my solution using eustf at hotmail dot com's suggestion of $_SERVER['PHP_SELF']: |