Forum Moderators: coopster
I've got a few lines of php code I call at the beginning of all the pages on my website (with the exception of files in two sub-directories) and I'm trying to think of the most efficient way to include that code.
Right now I have the lines at the top of each file. So if I have to change something, I need to edit each file. Obviously a pain that could be fixed by calling the code in an include.
I'm just thinking of what the most efficient way of doing this would be? For example, so that it would maybe cache the include or reduce a call to the server by putting the code somewhere else, anything like that.
Any suggestions?
you could look at auto_prepend [php.net]
example -
if you want to include a.inc, b.inc and c.inc on all pages
file - include.php
<?php
include 'a.inc';
include 'b.inc';
include 'c.inc';
?>
Then if you need to edit the includes just change them here.
So if I have to change something, I need to edit each file.
I couldn't understand this part. If you have included your files once, how many times would you need to rename the files and change those lines to include the right file name.
There seems to be a sign that you might be getting into one of the Top 100 Signs That You are Writing Spaghetti Code in PHP [webmasterworld.com]