Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where do you store your PHP script configurations like DB access data?

Tags:

php

I have an config.php file where I simply make an huge array that contains all the framework configuration. Also the database source string thing like "mysql:host=localhost;dbname=mydb" (whats that called, btw?) and username + password for DB. I'm afraid this is:

  1. stupid
  2. not good; better solution there
  3. not secure (?)

so how do the PHP experts do that?

like image 610
openfrog Avatar asked Dec 27 '09 12:12

openfrog


1 Answers

If you have a www, httpdocs or public_http folder or something like that, where your php application is situated, then it is good practice to put the config file outside of that folder, and just access it like this:

include "../config.php";

Nobody can gain access to that file without FTP access, and so it's relatively safe compared to having it in the application folder.

If you don't have such a folder, you can create one, and make a .htaccess file in the root, which redirects all requests to that folder. There are many different ways to do that, but that's a different question all together.

like image 71
Tor Valamo Avatar answered Oct 10 '22 21:10

Tor Valamo