note 116619 deleted from reserved.variables by salathe

From: Date: Fri, 06 Feb 2015 13:34:10 +0000
Subject: note 116619 deleted from reserved.variables by salathe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-201638@lists.php.net to get a copy of this message
Note Submitter: nakforme at najeeb dot com ---- 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? http://toronto-personal-injury.lawyer/ <?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> :) ?>

« previous php.notes (#201638) next »