Jump to content

Database Settings Form


The Little Guy

Recommended Posts

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.