note 83066 added to function.include

From: Date: Thu, 08 May 2008 16:38:02 +0000
Subject: note 83066 added to function.include
Groups: php.notes 
Request: Send a blank email to php-notes+get-139185@lists.php.net to get a copy of this message
As a rule of thumb, never include files using relative paths. To do this efficiently, you can define constants as follows: ---- <?php // prepend.php - autoprepended at the top of your tree define('MAINDIR',dirname(__FILE__) . '/'); define('DL_DIR',MAINDIR . 'downloads/'); define('LIB_DIR',MAINDIR . 'lib/'); ?> ---- and so on. This way, the files in your framework will only have to issue statements such as this: <?php require_once(LIB_DIR . 'excel_functions.php'); ?> This also frees you from having to check the include path each time you do an include. If you're running scripts from below your main web directory, put a prepend.php file in each subdirectory: -- <?php include(dirname(dirname(__FILE__)) . '/prepend.php'); ?> -- This way, the prepend.php at the top always gets executed and you'll have no path handling headaches. Just remember to set the auto_prepend_file directive on your .htaccess files for each subdirectory where you have web-accessible scripts. ---- Server IP: 69.147.83.197 Probable Submitter: 189.180.78.96 ---- Manual Page -- http://www.php.net/manual/en/function.include.php Edit -- https://master.php.net/note/edit/83066 Del: integrated -- https://master.php.net/note/delete/83066/integrated Del: useless -- https://master.php.net/note/delete/83066/useless Del: bad code -- https://master.php.net/note/delete/83066/bad+code Del: spam -- https://master.php.net/note/delete/83066/spam Del: non-english -- https://master.php.net/note/delete/83066/non-english Del: in docs -- https://master.php.net/note/delete/83066/in+docs Del: other reasons-- https://master.php.net/note/delete/83066 Reject -- https://master.php.net/note/reject/83066 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#139185) next »