Jump to content

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);

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.