The Little Guy Posted July 4, 2012 Share Posted July 4, 2012 I am trying to think of the best way to store database login information (user, pass, host, database) that can be edited/updated in a form, and still not be view able in a browser without the use of htaccess, and still resided in a sub directory of the root. I was thinking of just writing the php code to a file whenever the form is submitted, but that doesn't seem logical. Any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/265182-database-settings-form/ Share on other sites More sharing options...
requinix Posted July 4, 2012 Share Posted July 4, 2012 Two most common options: 1. Put it in a file outside the web root. 2. Put it in a PHP file wherever. $config = array( "db" => array( "username" => "foo", "password" => "bar" ) ); ?> include "config.php"; $config["db"]["username"] = "new value"; file_put_contents("config.php", ''); Remember to chmod(0600) the file so no one else can read it. that can be edited/updated in a form Why would it be? It's something you want people to configure using an easy UI tool? Not a one-time thing? Quote Link to comment https://forums.phpfreaks.com/topic/265182-database-settings-form/#findComment-1359040 Share on other sites More sharing options...
The Little Guy Posted July 4, 2012 Author Share Posted July 4, 2012 that can be edited/updated in a form Why would it be? It's something you want people to configure using an easy UI tool? Not a one-time thing? Yes, it is a UI tool for my CMS, in case someone changes the name of the db, username, password, host, etc. and they don't know php they can easily do it via this instead of finding the file and trying to figure it out. Quote Link to comment https://forums.phpfreaks.com/topic/265182-database-settings-form/#findComment-1359043 Share on other sites More sharing options...
scootstah Posted July 4, 2012 Share Posted July 4, 2012 Here's some food for thought. If the database credentials are changed before the file is updated, they are still going to have to manually update the file. I say this because the form will probably be in a restricted admin panel somewhere, and you won't have any way to validate someone if you can't connect to the database. It doesn't sound like something that is terribly useful. Also, if they can buy hosting & domain, upload the files to the server, run the initial configuration, create a database, and then change all the database credentials: they can probably change the text between two quotes. If you're still interested, requinix seems to have your answer. Quote Link to comment https://forums.phpfreaks.com/topic/265182-database-settings-form/#findComment-1359046 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.