Custom configuration file

Discussion in 'Web Design and Development' started by Schonert, Dec 19, 2011.

  1. Schonert macrumors newbie

    Nov 19, 2011
    South Africa
    I'm bussy making a client management system, and I'm trying to make it as flexable as posible. I'm doing that by making a configuration file that stores all the information, such as; login name and password, database login and a few other things. By doing that there no need to dig into every class file and changes the variables. Now making a config file was no problem. I made a php file, so i basically just require it into my main class and spread the info out. My problem is, that i also want to be able to change these variables. Change the login name/pass and so on, so that it becomes more userfriendly.

    I've been surfing around the internet looking for a solution, but with out any luck. I'm sure i just don't know the right terms, to make a decent search. If anyone knows anything about the subject, please guys, do not hesitate!

    So basically what i need, is a method to change and save a php file, through a php file..
  2. pjo macrumors regular

    Feb 20, 2006
    you can install CMS systems like Joomla to see how they do it.


    1. the file needs to be in a directory writable by the web server (also the file itself needs to be writable by the web server).

    2. you read your variables as normal then just generate values for ALL required variables and use php fwrite and friends to overwrite the original file.

    you can read up on manipulating files using php to figure out how to do things like just replacing only changed values if you have a huge enough configuration file.

    I'd be weary of doing this though. You at the bare minimum require a .htaccess (if using Apache or whatever the equivalent is for your web server) to restrict access to that configuration file or you risk having database credentials out in the open.

    Also, having configuration files writable by the webserver needs to be handled carefully. Lots of possible holes exist once you do that.
  3. Schonert thread starter macrumors newbie

    Nov 19, 2011
    South Africa
    Thank you pjo, you've got a lot of good point there. i Will be honest with you, i'm only doing this, because this is the only solution i could think of. I want to be able to go in and edit all the admin info, from an interface, not through files, and this was the only solution i could come up with. I am WIDE open for other better or different alternatives. This is not my best field, wich makes advice priceless for me.

    Do you have any other suggestions, on how to solve this issue of mine? A different method maybe?

Share This Page