iMiles Posted June 2, 2010 Share Posted June 2, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/203663-correct-way-to-work-with-configuration-files/ Share on other sites More sharing options...
gwolgamott Posted June 2, 2010 Share Posted June 2, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/203663-correct-way-to-work-with-configuration-files/#findComment-1066785 Share on other sites More sharing options...
premiso Posted June 2, 2010 Share Posted June 2, 2010 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); Quote Link to comment https://forums.phpfreaks.com/topic/203663-correct-way-to-work-with-configuration-files/#findComment-1066789 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.