Jump to content

Correct Way to Work With Configuration Files?


iMiles

Recommended Posts

Hey all,

 

I'm working on a Content Management System, and need some help. When you install my CMS, it asks for a MySQL Host, Username, and password. Somehow I need to write these variables to a config file to be accessed later. I'm looking for the correct way to go about this :)

 

 

What exactly is the reason to access them later for?

 

So someone can answer this more further, but my first inclination is say why mess with the security risk of having your information in a config file? why not just use cookies, but then again don't know the exact scenario

What exactly is the reason to access them later for?

 

So his script can access the database. And storing the database information in cookies is just well...not advised, for lack of a better word.

 

As for "somehow write these variables to a file" what is wrong with something like:

$config = <<<CONFIG
<?php
$mysqlHost = '{$valuefromform}';
$mysqlUser = '{$valuefromform}';
$mysqlPassword = '{$valuefromform}';
$mysqlDatabase = '{$valuefromform}';
?>
CONFIG;

$fh = fopen('config.php', 'w');
fwrite($fh, $config);
fclose($fh);

// lock file down to only be read by webserver / script.
chmod('config.php', 0600);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.