View Full Version : Keeping site config in the DB

04-04-2007, 05:30 PM

I have gathered some variables in config.php, such as $sitename, $siteurl, $root_path, $enable_registrations etc.

For me it is no problem to keep it in the config.php, I can live with it, whenever I need to change something, I can edit it.

But for other people, who don't have FTP or file editing knowledge, I want to make this info accessible in the Admin section.

I can prepare a config DB table and keep the values there. But there are some variables which are called with every page load. For example $sitename appears in the header.php or footer.php. That could make too many DB requests. On the other hand, config.php gets included with every page load too :)

So that makes me think about using session variables. Get the values at the start, assign them to session vars and change the session vars when admin changes them. Is this a smart way?

04-04-2007, 05:35 PM
Na use a cache file.

function get config values {
if cache file exists, use it, if not
query database for config values
create cache file
return info


Then just clear the cache file when the info is changed. The function will auto check for the file and requery when necessary

04-04-2007, 05:42 PM
Sounds good.
Where to create the cache file, which extension?

Can you be more specific?


04-04-2007, 05:55 PM
Extension and where is completely up to you. Though I suggest making the file, or the folder it resides in not readable from outside.

Either by using an .htaccess file or putting it outside of the webroot.

04-04-2007, 05:59 PM

I use .cache and setup a cache folder in the same dir of the html folder, which is outside of the root dir :)