If anyone is familiar with Mambo Content Manager, I would like to know how the system saves configuration settings to configuration.php. I would like to implement this idea into my own site, but I cant figure out how a PHP page rewrites and saves another page on the server. Anyone know? Thanks!

If anyone is familiar with Mambo Content Manager, I would like to know how the system saves configuration settings to configuration.php. I would like to implement this idea into my own site, but I cant figure out how a PHP page rewrites and saves another page on the server. Anyone know? Thanks!

Mambo uses XML files to model configuration. Then it writes the configuration to regular PHP files.

I haven't looked at Mambo since 4.5 so I don't know if they still do that. Joomla, the fork of Mambo since 4.5 now uses XML to model the configuration, and writes configuration values to .ini files.

The process of saving a configuration file is quiet simple.

Say you have a config file named: config.php

<?php

$config = array();

$config['sitename'] = 'My website naem';
$config['url'] = 'http://example.com/';

?>

This config.php contains an array $config with two indexes, "sitename" and "url".

To read the file, and write it back:

require_once('config.php');

$lines = array();
// generate an array with the lines for each value to be written to the config file
foreach($config as $name=>$value) {
   $lines[] = '$config[\''.$name.'\'] = \''.addslashes($value).'\';';
}

// generate the string for the whole file
$str = '<?php

$config = array();

';

$str .= implode("\n", $lines);

$str .= '

?>';

// write this string to the file
file_put_contents('config.php', $str);

Normally, you want to write the config values back after they are changed. So if you modify the values of $config then they will be reflected when the file is saved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.