Friday, June 30, 2006

Global Include Trick

As the major part in my PHP Application Architecture, this trick allows you to include a global file at the top of your scripts. It has the benefit of not keeping the file location or name inside of each individual PHP script.

I was able to accomplish this by using Apache's SETENV directive. It registers a variable visible to all scripting languages through either an entry in either an .htaccess or httpd.conf file. Then in each of my PHP scripts I include that variable's contents.

A very handy trick, if you ask me.
Source:


/*
* This goes into the Apache configuration file (or .htaccess)
*
* SetEnv GLOBAL /mypage/local/application.php
*
* Then put the below PHP into each of your scripts... enjoy!
*
*/

require(getenv("GLOBAL"));

?>

No comments: