PDA

View Full Version : writing configuration files in php?


aximbigfan
02-03-2008, 01:43 AM
Anyone know how to write configuration files in PHP?

I have though of a few ways, but non work really well.

Basically, I just want to write variables and values, to be used by a PHP app for its configuration.

For example

have a webui where the user says that they want "white" to be a background color, and "blue" be the text color. So they click on submit, and the PHP script opens config.php, and writes the following to it...

$bgcolor = "white";
$textcolor = "blue";


Chris

y2kbugger
02-03-2008, 02:47 AM
would this be per user, or like a site admin?

Jizzler
02-03-2008, 03:44 AM
If you're on php5, file_put_contents() wraps up fopen(), fwrite() and fclose() into one nice little function.

// Possibly done during account creation with default values
$userInfo = array('BgColor' => '#FFFFFF', 'TxtColor' => '#000000');
file_put_contents('user.info', serialize($userInfo));

// Pulling the values...
$userInfo = unserialize(file_get_contents('user.info'));

Depending on how you identify users, could save them as $username.'whatever'.

aximbigfan
02-03-2008, 04:34 AM
If you're on php5, file_put_contents() wraps up fopen(), fwrite() and fclose() into one nice little function.

// Possibly done during account creation with default values
$userInfo = array('BgColor' => '#FFFFFF', 'TxtColor' => '#000000');
file_put_contents('user.info', serialize($userInfo));

// Pulling the values...
$userInfo = unserialize(file_get_contents('user.info'));

Depending on how you identify users, could save them as $username.'whatever'.

Thanks Jizzler!

Chris