Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jan 2006
    Posts
    377
    Thanks
    8
    Thanked 1 Time in 1 Post

    Keeping site config in the DB

    Hello,

    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?

  • #2
    Regular Coder
    Join Date
    Oct 2005
    Location
    Right Here
    Posts
    654
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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

  • #3
    Regular Coder
    Join Date
    Jan 2006
    Posts
    377
    Thanks
    8
    Thanked 1 Time in 1 Post
    Sounds good.
    Where to create the cache file, which extension?

    Can you be more specific?


  • #4
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    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.

  • #5
    Regular Coder
    Join Date
    Oct 2005
    Location
    Right Here
    Posts
    654
    Thanks
    1
    Thanked 0 Times in 0 Posts
    ^^

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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •