note 109445 deleted from function.include by googleguy
| From: | googleguy@php.net | Date: | Wed, 01 Aug 2012 06:50:53 +0000 |
| Subject: | note 109445 deleted from function.include by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-189544@lists.php.net to get a copy of this message | ||
Note Submitter: serpent at paradise dot net dot nz
----
1. Don't use include to include any kind of config.php file if you can avoid it, it's
inadvisable from a security standpoint. You should use a config.ini file outside of your www tree.
See http://php.net/manual/en/function.parse-ini-file.php
2. Depending on whether your server supports it, you can set a "root" directory variable
for your scripts in your .htaccess file e.g. if your scripts are under /var/www/application you can
set a variable in /var/www/application/.htaccess like:
SetEnv APPROOT '/var/www/application'
This variable will appear in the $_SERVER superglobal. You can then use it in the head of a php
file. For example, if a particular file is in /var/www/application/classes, you might put this:
<?php
chdir($_SERVER['APPROOT']);
?>
Then you can include files relative to the application root directory without worrying about which
directory it's in, or which directory the file that's including it in turn is in e.g.
<?php
include('functions/strings.php');
?>
Would include /var/www/application/functions/strings.php, not
/var/www/application/classes/functions/strings.php
If you have to move your application, you can easily edit the "APPROOT" in one place.