-2

There seem to be a lot of similar questions about this issue with no concise answers.

I have MySQL database that I need to connect to from several different PHP pages. In the past I have just included authentication information for the database in every PHP page, but this seems like a terrible day, both from a reusability perspective and from a security standpoint.

Where can I store credentials to my MySQL database so that I can refer to one location from several different php files to authenticate with the database?

Verbal Kint
  • 425
  • 1
  • 3
  • 20
  • Use common class to connect Mysql. Use that class where you need database connection. Make that class to load those credentials from some safe place. You should use some light framework like codeigniter. – Hardy Aug 06 '16 at 20:04

2 Answers2

0

Yes It's not a good idea and cumbersome to write db connection parameters in each and every page, specially when there are lot of page. Make a dedicated php file for this purpose only and use it via require_once() whenever required.

jonju
  • 2,711
  • 1
  • 13
  • 19
0

I am assuming you are including a connection file require()

you cant really do that you could store the values in a text file somwhere and if you know how to use php read file and get the text and then filter it

else you could take a look at an mvc framework they are more build to suit this nature

or you could store the values into a folder and put an htaccess file in it to prevent users from indexing the folder

Reuben Gomes
  • 878
  • 9
  • 16