note 104265 added to function.require-once

From: Date: Sat, 04 Jun 2011 18:46:39 +0000
Subject: note 104265 added to function.require-once
Groups: php.notes 
Request: Send a blank email to php-notes+get-180257@lists.php.net to get a copy of this message
If your code is running on multiple servers with different environments (locations from where your scripts run) the following idea may be useful to you: a. Do not give absolute path to include files on your server. b. Dynamically calculate the full path (absolute path) Hints: Use a combination of dirname(__FILE__) and subsequent calls to itself until you reach to the home of your '/index.php'. Then, attach this variable (that contains the path) to your included files. One of my typical example is: define('__ROOT__', dirname(dirname(__FILE__)); require_once(__ROOT__.'/config.php); instead of: require_once('/var/www/public_html/config.php); After this, if you copy paste your codes to another servers, it will still run, without requiring any further re-configurations. ---- Server IP: 69.147.83.197 Probable Submitter: 110.34.0.242 (proxied: 116.66.193.69) ---- Manual Page -- http://www.php.net/manual/en/function.require-once.php Edit -- https://master.php.net/note/edit/104265 Del: integrated -- https://master.php.net/note/delete/104265/integrated Del: useless -- https://master.php.net/note/delete/104265/useless Del: bad code -- https://master.php.net/note/delete/104265/bad+code Del: spam -- https://master.php.net/note/delete/104265/spam Del: non-english -- https://master.php.net/note/delete/104265/non-english Del: in docs -- https://master.php.net/note/delete/104265/in+docs Del: other reasons-- https://master.php.net/note/delete/104265 Reject -- https://master.php.net/note/reject/104265 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#180257) next »