1

I am making a custom CMS in PHP and I want to know what the best way would be to create a config file for it. I want it where I can change the variables from within the admin panel I am going to add. I have not messed with the filesystem functions before or any other file functions so I am not sure what would be the best approach. Thanks!

4 Answers 4

2

An .ini file can be structured quite well and you'll be able to update just sections of. Compared to a straight PHP configuration it can be edited with an easier syntax.

To parse the .ini file into a PHP array, use the function parse_ini_file()

Sign up to request clarification or add additional context in comments.

1 Comment

ini files are more what I am looking for, thank you! I wanted it to be human-readable so I could easily change values in case I can't get into the database for whatever reason. And like you said, I can just update sections.
2

If you want a human-readable config file format then look into parse_ini_file(). You'll need to be able to write to the file too, see: create ini file, write values in PHP. There's a PEAR Package Config_Lite that seems like it should work too.

If readability doesn't matter then save it to a database.

Comments

1

If you want the variables to be changeable via an admin web interface, store those variables in the database like any other CRUD data.

3 Comments

i have always wondered if it was necessary to store/how to store into the database a single line data, like say "footer credits" and "site name". a config file is better in this situations.
@Joseph Why would you need a web interface to change the site name? It's hardly something you'd do on a regular basis.
the part of the purpose of a CMS is to make it easy for non-techy people to edit site settings as well as provide access to a lot of off-site configurations from within the admin section of the site.
1

The best idea I think is to use MySQL to store the data.

However, if you cannot do that for some reasons, then I would suggest to make it an XML file and then you can get variables from SimpleXML, and such, you can view all and put their values to a form. Then, the destination PHP could easily make a string like "<val1>".$_POST["value1"]."</val1><val2>".$_POST["value2"]."</val2>". Finally, it would save the file through simple file system functions, which you can learn with googling "php file write".

Or another idea is the parse_ini_file() which is already mentioned.

If you don't understand something, ask. Or Google!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.