I am debating on using either a configuration.ini
or config.json
for my administration dashboard I am designing. I like that ini
is more for configuration purposes but with todays interest in JSON it seems more logical for the configurations be designed with json in mind.
Question here is should I use json for sure? And secondly I have this hack currently on my configuration.ini
file which prevents the file being seen publicly.
;<?php exit(); __halt_compiler();
; //to stop script execution if not used in our best interest!
; //remember this format
//ini stuff
;?>
I was wondering if I could use this with the json file as well? I haven't tested it just because I didn't want nothing strange completely screwing everything up.As well as a good description as to why this works, now I know this won't work specifically with JSON since the ;
is ini
based commenting so could it be transformed to //
or /**/
for json?
For interest purposes this is currently my admin__autoload.php
page
set_include_path(dirname($_SERVER["DOCUMENT_ROOT"]));
$ini = parse_ini_file("configurations.ini",true);
foreach($ini as $section=>$values) {
foreach($values as $key=>$value ) {
define("__".strtoupper($key)."__",$value);
}
}
spl_autoload_register(function($class) {
if(!file_exists(get_include_path(). DIRECTORY_SEPARATOR .__ADMIN__."classes/{$class}.php")) {
echo get_include_path(). DIRECTORY_SEPARATOR .__ADMIN__."classes/{$class}.php does not exist";
} else {
include_once get_include_path(). DIRECTORY_SEPARATOR .__ADMIN__."classes/{$class}.php";
}
});
__ADMIN__
was created with the foreach loop from my ini file.
I think you're asking two different questions here.
The answer to 2 is easy. Don't put your configuration files in your public document root.
As far as choosing between INI or JSON, it's rather subjective without understanding the use case very clearly.
INI is more expressive for the reader but harder to parse. JSON is quite portable as a serialization format, but harder to read as a human.
So if you're manually editing the configuration file a lot, it makes sense to go with INI as its slightly disambiguated than JSON. If you're doing the editing through an autonomous process or one that otherwise requires portability across disparate systems, JSON may be more convenient.
A third alternative is YAML, which is a good middle ground between the human-readable aspect of INI, and the portability of JSON.