note 109445 added to function.include

From: Date: Wed, 18 Jul 2012 00:26:32 +0000
Subject: note 109445 added to function.include
Groups: php.notes 
Request: Send a blank email to php-notes+get-189274@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/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. ---- Server IP: 202.89.58.1 Probable Submitter: 113.130.120.166 ---- Manual Page -- http://www.php.net/manual/en/function.include.php Edit -- https://master.php.net/note/edit/109445 Del: integrated -- https://master.php.net/note/delete/109445/integrated Del: useless -- https://master.php.net/note/delete/109445/useless Del: bad code -- https://master.php.net/note/delete/109445/bad+code Del: spam -- https://master.php.net/note/delete/109445/spam Del: non-english -- https://master.php.net/note/delete/109445/non-english Del: in docs -- https://master.php.net/note/delete/109445/in+docs Del: other reasons-- https://master.php.net/note/delete/109445 Reject -- https://master.php.net/note/reject/109445 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#189274) next »