note 64443 added to reserved.variables

From: Date: Fri, 14 Apr 2006 13:18:23 +0000
Subject: note 64443 added to reserved.variables
Groups: php.notes 
Request: Send a blank email to php-notes+get-108065@lists.php.net to get a copy of this message
So you have an application in your web space, with a URL such as this: http://<host>/<installation_path>/ 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> :) ?> ---- Server IP: 85.116.0.130 Probable Submitter: 87.74.54.127 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/reserved.variables.php Edit -- http://master.php.net/note/edit/64443 Del: integrated -- http://master.php.net/note/delete/64443/integrated Del: useless -- http://master.php.net/note/delete/64443/useless Del: bad code -- http://master.php.net/note/delete/64443/bad+code Del: spam -- http://master.php.net/note/delete/64443/spam Del: non-english -- http://master.php.net/note/delete/64443/non-english Del: in docs -- http://master.php.net/note/delete/64443/in+docs Del: other reasons-- http://master.php.net/note/delete/64443 Reject -- http://master.php.net/note/reject/64443 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#108065) next »