# writing configuration files in php?



## aximbigfan (Feb 3, 2008)

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 (Feb 3, 2008)

would this be per user, or like a site admin?


----------



## Disparia (Feb 3, 2008)

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 (Feb 3, 2008)

Jizzler said:


> If you're on php5, file_put_contents() wraps up fopen(), fwrite() and fclose() into one nice little function.
> 
> 
> ```
> ...



Thanks Jizzler!

Chris


----------

