Home | Scripts | How To's | About


Global Include Trick

View Comments

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 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"));
 
?>
 


Comments (Last 10): [Show All]


Pharmk879February 21st, 2013 @ 08:24AM

Very nice site!

Pharmb306February 21st, 2013 @ 08:24AM

Very nice site! cheap cialis http://aieypxo.com/toasas/4.html

Pharmd589February 21st, 2013 @ 08:24AM

Very nice site! [url=http://aieypxo.com/toasas/2.html]cheap cialis[/url]

Pharmf911February 21st, 2013 @ 08:24AM

Very nice site! <a href="http://aieypxo.com/toasas/1.html">cheap viagra</a>

Pharmk32February 21st, 2013 @ 08:24AM

Hello! dbddcff interesting dbddcff site! I'm really like it! Very, very dbddcff good!

DbotMay 21st, 2012 @ 04:42PM

I also like to include them in /var/www/globals/domain.php since /var/www is shared on most systems, and the fact that I never care about windows systems LOL...

putting it in the httpd.conf like this is handy too if you are only looking for one set of globals.

swhitemanMay 21st, 2010 @ 05:48PM

Hey, cool tip from a million years ago! I just wanted to comment that this doesn't work if you intend to include a "cleanser" to protect uploaded/overwritten/tampered PHP files -- yes, yes, we should as thoroughly as possible eliminate any possibility of executing uploaded files server-side, but vulnerabilities definitely happen, like this 0day one right here:

http://www.webhostingtalk.com/showthread.php?p=6807475#post6807475

Since the global include is still happening within the page itself, it isn't quite global enough to help you out! Anyway, just a obvious note that was on my mind after reading about the nginx vuln....

Matt BJanuary 09th, 2007 @ 01:58PM

NB This requires some tweaking under FastCGI as the environmental variables from the .htaccess file aren't directly available. You can usually access the variable from inside the $_SERVER superglobal variable, however.

HTH!
Matt

Matt BMay 26th, 2005 @ 05:04PM

Thanks for the tip Serge :)

 
Post Comment:

Use the following verification number: v8jda2zj3gm

Name 
Comment 
Verification 



eBay Sniper