Working With A PHP Configuration File

TRUE or FALSE: “It’s easier to update one file or 10 files.” This statement is True.

The concept of a configuration file is that it stores data in one location that any other file on the web site can access. The data that is stored in a configuration file can be unlimited, but usually contains data such as by not limited to the following:

  • MySQL Database, Username and Password
  • Document Root Folder
  • To use Cookies or Sessions
  • Set time limit for Sessions
  • Custom variables for web applications
  • and etc.

Too many times I’ve assumed responsibility for a web site where the previous developer didn’t make use of a PHP configuration file. Often the most common things I find is that the MySQL information is on every single page, and in the even that we have to change the password, I have to either setup a config file, or change every file that’s using that information.

I opt for changing each page to use the configuration file and set the MySQL information in just one location. This makes my work a lot easier in the future. I can now set other information in this config file as well based on the site and it’s purpose.

The problem with having to change the same data in multiple files takes additional time and presents a larger margin for human error, where with a config file change can be made once, and human error can be corrected much quicker and easier.

Leave a Reply

Spam Protection by WP-SpamFree