note 14996 deleted from function.include by philip

From: Date: Fri, 02 Nov 2001 07:05:28 +0000
Subject: note 14996 deleted from function.include by philip
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-20280@lists.php.net to get a copy of this message
Here is a quick way to include files relative to the web server root and protect yourself from including the same file more than once. May look familliar to VC++ users. if (! isset($FILE_f7184dcae9bfac2985d8ce2b274473d1_INCLUDED)) { $FILE_f7184dcae9bfac2985d8ce2b274473d1_INCLUDED = 1; // import.php // Author: Steven Brendtro // Description: // This function allows for SAFE file inclusion // relative to web server root. It is safe in // that it checks to see if the file has already // been included before trying to reinclude the // the file. // Usage: // Simply include this file in your PHP program, // then call import($strRelPath) where $strRelPath // is a filename/path relative to your web server root. // Example: // include($DOCUMENT_ROOT . '/includes/import.php'); // import('/includes/myIncludedFile.php'); function import($strRelPath) { $varName = "FILE_" . md5($strRelPath) . "_INCLUDED"; global $$varName; if (! isset($$varName) ) { global $DOCUMENT_ROOT; include($DOCUMENT_ROOT . "/" . $strRelPath); $$varName = 1; } } // End import($strRelPath) } // End isset($FILE_..._INCLUDED)

« previous php.notes (#20280) next »