Is possible to edit config file at runtime? I'm developing a module manager and this has to be able to change some aspects of the configuration dynamically.
This means being able to read and this writte this file at runtime, and modify for example this line.
$config ['WebTitle'] = 'foo';
Some tips?
PD: I dont wont to create a new table in database to store this configuration. Alternatives?
EDIT: After searching for some time I found an answer quite similar to what I'm looking for, but have not had success.
It might. Htaccess block this?
Link to response : link
It sounds like you want to actually modify the config file. If so, yes, you can do it. You will need to make sure the file is writable by the web server. Then just fopen() the file, fread() it into memory, change what's needed, then fwrite() it back out again. Easy! :)
Please keep in mind there is a security risk if you are in a shared hosting situation.
If you are doing a setup process, you may want to check permissions with a call to fileperms(). Then if the permissions are not correct, tell the user they will need to ftp into their account and make the file writable. Then, after setup is done, tell the user to mark the file as non-writable again.
Based en your second comment, yes, there is a way of changing the config values depending on the website: All you have to do is include an if (or switch) statement with your configuration variables in the config.php file. This way you may have a multidomain site with the same CI core:
if (($_SERVER['HTTP_HOST']=='localhost') or ($_SERVER['SERVER_ADDR']=='127.0.0.1')) {
// Config array web site for development
} else if ($_SERVER['HTTP_HOST']=='www.website1.com') {
// Config array website1
} else if ($_SERVER['HTTP_HOST']=='www.website2.com') {
// Config array website2
} ... and so on