Jump to content

Choosing a good config structure


Travis1128

Recommended Posts

I am in a bit of a debate on which structure I should use and want your guy's opinion,

 

#######################
# Configuration Array #
#######################
$config = array(
"mysql" => array(
	"db1" => array(
		"name" 		=> "example",
		"username"	=> "exampleUser",
		"password"	=> "passw0rd",
		"host"		=> "localhost",
	),
),
"base_info" => array(
	"baseURL"		=> "http://example.com",
),
"paths" => array(
	"resources"		=> "/resources/",
	"template"		=> "/resources/template/",
	"library"		=> "/resources/library/",
	"images"		=> "/images/",
	"css"			=> "/css/",
	"js"			=> "/js/",
),
);

#####################
# Defined Variables #
#####################
# MySQL
define('DBHOST', 	'localhost');
define('DBNAME', 	'example');
define('DBUSER', 	'exampleUser');
define('DBPASS', 	'passw0rd');
# Base Information
define('BASEURL', 	'Http://example.com');
# Paths
define('RESOURCE_PATH',	'/resources/');
define('TEMPLATE_PATH',	RESOURCE_PATH . 'template/');
define('LIBRARY_PATH', 	RESOURCE_PATH . 'library/');
define('IMAGES_PATH', 	'/images/');
define('CSS_PATH', 	'/css/');
define('JS_PATH',	'/js/');

 

Which one would you choose? Or would you do it a different way?

Link to comment
https://forums.phpfreaks.com/topic/244366-choosing-a-good-config-structure/
Share on other sites

Both work well, and I've seen both used in major projects. Which ever one is easier for you. I've even seen singleton config classes.

 

Thank you for your swift reply. I believe I prefer the defined version as it gets to the point and is easier to output etc.

 

Now I want to use $_SERVER["DOCUMENT_ROOT"] but I have been hearing mixed thoughts about it and it possibly being a security hole in your script. How? I am not sure completely but I have been reading and some people have said it poses as a threat.

 

What is your opinion on it?

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.