D.R.Y. out those useful PHP scripts 

D.R.Y. – ‘Don’t repeat yourself’

I have a few PHP scripts that come in handy on a lot of different sites. The issue I ran into was that if i needed to make an update to one of these useful scripts, I’d have to go find all instances of that script, and update them across many domains.

There’s ways of doing this with ninja SED/grep styles. But a better way may to be make a folder just below the domains directory, and include files from that directory as needed.

In the example below im stepping backwards from the public html directory into my scripts directory.

include('../../../phpIncludes/test.php');

Thats about the extent of it, and im sure this can be cleaned up a bit.  I was using the scandir() function to find my way to the proper path by echoing out the files of the current directory.

I was also reading open_dir() can cause issues with this technique, and if open_dir() is active it can php scripts from editing lower than the domains’s root. open_dir() is a good safety net, but is also prevents some tricks and techniques that just need to happen. A good example is in WordPress sites (as of 2.9) the Media library will throw errors with open_dir() enabled.