Jump to content

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.