[eluser]Twisted1919[/eluser]
Ok, so until yesterday, i was saving my $config items into database, then in My_Controller, i was overwriting them with the database values using set_item() method but now i have much too many items, over 60 params and i don't want to query the database for the config everytime when somebody enters the site, is too much for nothing .
So, i came up with the overwriting config.php file solution , i have a custom library that connects to ftp, changes the mod of the config file to 0666, then it makes need changes using regexes, and after that, it changes the config file back to 0644 and closes the ftp connection .
So i end up having somethink like :
Code:
$file = read_file(APPPATH.'config/config.php');
[...]
//$config values are taken from $_POST array
$config['sitename'] = 'My Site';
$config["site_title"] = 'Maybe Something Else';
[...]
//I am taking the new $config items from an array, so it's 'TRUE' instead of TRUE, you get the point ...
[...]
<?php
foreach($config AS $item=>$value)
{
if($value == 'TRUE' || $value == 'FALSE' || is_numeric($value))
{
$file = preg_replace('/(\$config\[(\'|\"){1}'.$item.'(\'|\"){1}\])(\s|\t)*=?(\s|\t)*(TRUE|FALSE|\d+)(\s)*;/ix','$config[\''.$item.'\'] = '.$value.' ;',$file);
}
else
{
$file = preg_replace('/(\$config\[(\'|\"){1}'.$item.'(\'|\"){1}\])(\s|\t)*=?(\s|\t)*(\'|\"){0,1}.*(\'|\"){1}(\s)*;/ix','$config[\''.$item.'\'] = \''.$value.'\' ;',$file);
}
}
write_file(APPPATH.'config/config.php', $file);
?>
Now , i'm not always sure of what value will have an item, by default i can wrap it in single quotes, then the client may add other single quote in his string, and could break all the config ...
Is there another way to do this , in a more clean and efficient way ?
Any help is appreciated.
Thanks.
P.S: All these items, will be overwritten from POST forms .