Jump to content

MySQL username/password usage


beyuch

Recommended Posts

Hello everyone...

 

Ive been using MySQL and PHP for some time now but my code has never been right.

 

In my code I always store the username and password.. the reason for this is because I have always required a quick and dirty solution and it did the job.

 

Anyway... the reason I am posting this is because I want some advise on the best way to store a username/password that can be used by all scripts.

 

Typically I see on sites and in CMSs such as Joomla, that the username/password is stored in a configuration/config file and is 'included' - in plain text.

 

Is this the way to do it?

 

Is there a better solution?

 

 

Link to comment
https://forums.phpfreaks.com/topic/91061-mysql-usernamepassword-usage/
Share on other sites

Just store it out of the document root and call it a day....

 

The way I'm doing this right now is by having an init.php and a config.php. All of my files include the init.php file, which simply references the config file. As long as I have the path in the init.php file right, all the other files will have access to the variables without having to implicitly include it.

 

So, then you just move the config.php file (the one with db credentials) to a place not publicly accessible, or completely out of the public_html directory. Then change the reference in the init.php file. It's very easy and makes the code easy to move and update.

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.