note 109445 modified in function.include by aharvey
| From: | aharvey@php.net | Date: | Mon, 23 Jul 2012 07:01:57 +0000 |
| Subject: | note 109445 modified in function.include by aharvey | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-189365@lists.php.net to get a copy of this message | ||
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.
--was--
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/functions/strings.php, not /var/www/classes/functions/strings.php
If you have to move your application, you can easily edit the "APPROOT" in one place.
http://php.net/manual/en/function.include.php