note 104265 modified in function.require-once by googleguy
| From: | googleguy@php.net | Date: | Sat, 24 Nov 2012 20:38:39 +0000 |
| Subject: | note 104265 modified in function.require-once by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-192132@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:
<?php
define('__ROOT__', dirname(dirname(__FILE__)));
require_once(__ROOT__.'/config.php');
?>
instead of:
<?php 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.
[EDIT BY danbrown AT php DOT net: Contains a typofix (missing ')') provided by
'JoeB' on 09-JUN-2011.]
--was--
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:
<?php
define('__ROOT__', dirname(dirname(__FILE__)));
require_once(__ROOT__.'/config.php);
?>
instead of:
<?php 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.
[EDIT BY danbrown AT php DOT net: Contains a typofix (missing ')') provided by
'JoeB' on 09-JUN-2011.]
http://php.net/manual/en/function.require-once.php