Good practice for choosing a web configuration file saved in a php file?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
Hello I want to save the configuration of my web page in a php file.The idea is the configuration is available regardless of whether there is a connection or not to database. I want to be in php files to more secured even if there is not a file forbidding to read the file (json, txt ...). I need to edit the values or add new ones dynamically through the page rather than scrolling through the files.
To solve my problem I found 2 methods used:
1st to record everything in the form of an array:
<?php return array(
'host' => 'localhost',
'username' => 'root', );
2nd to record everything in a flat-file database, but I do not find one that writes the files in php except: This CodeIgniter Flat-File Database Library
Who can not work alone without CodeIgniter.
Basically, I've come to the second option if I find something similar to the example. The 1st option implies the use of 1 file that will be difficult to service and it is possible to break something when recording. You can also give other options to dynamically change the values and record them.
php config flat-file
add a comment |
Hello I want to save the configuration of my web page in a php file.The idea is the configuration is available regardless of whether there is a connection or not to database. I want to be in php files to more secured even if there is not a file forbidding to read the file (json, txt ...). I need to edit the values or add new ones dynamically through the page rather than scrolling through the files.
To solve my problem I found 2 methods used:
1st to record everything in the form of an array:
<?php return array(
'host' => 'localhost',
'username' => 'root', );
2nd to record everything in a flat-file database, but I do not find one that writes the files in php except: This CodeIgniter Flat-File Database Library
Who can not work alone without CodeIgniter.
Basically, I've come to the second option if I find something similar to the example. The 1st option implies the use of 1 file that will be difficult to service and it is possible to break something when recording. You can also give other options to dynamically change the values and record them.
php config flat-file
Why not use a sqlite database?
– Aleks G
Jan 3 at 8:32
What about a json_encode an array and writing as a flat file? To read, json_decode it back and voila.
– Kush
Jan 3 at 8:59
Aleks G - I need to be multiplatform window and UNICS. Kush - i can not find a flat file database with support for php files
– bedamusa
Jan 3 at 9:38
add a comment |
Hello I want to save the configuration of my web page in a php file.The idea is the configuration is available regardless of whether there is a connection or not to database. I want to be in php files to more secured even if there is not a file forbidding to read the file (json, txt ...). I need to edit the values or add new ones dynamically through the page rather than scrolling through the files.
To solve my problem I found 2 methods used:
1st to record everything in the form of an array:
<?php return array(
'host' => 'localhost',
'username' => 'root', );
2nd to record everything in a flat-file database, but I do not find one that writes the files in php except: This CodeIgniter Flat-File Database Library
Who can not work alone without CodeIgniter.
Basically, I've come to the second option if I find something similar to the example. The 1st option implies the use of 1 file that will be difficult to service and it is possible to break something when recording. You can also give other options to dynamically change the values and record them.
php config flat-file
Hello I want to save the configuration of my web page in a php file.The idea is the configuration is available regardless of whether there is a connection or not to database. I want to be in php files to more secured even if there is not a file forbidding to read the file (json, txt ...). I need to edit the values or add new ones dynamically through the page rather than scrolling through the files.
To solve my problem I found 2 methods used:
1st to record everything in the form of an array:
<?php return array(
'host' => 'localhost',
'username' => 'root', );
2nd to record everything in a flat-file database, but I do not find one that writes the files in php except: This CodeIgniter Flat-File Database Library
Who can not work alone without CodeIgniter.
Basically, I've come to the second option if I find something similar to the example. The 1st option implies the use of 1 file that will be difficult to service and it is possible to break something when recording. You can also give other options to dynamically change the values and record them.
php config flat-file
php config flat-file
edited Jan 3 at 8:56


Script47
10k42248
10k42248
asked Jan 3 at 8:30
bedamusabedamusa
11
11
Why not use a sqlite database?
– Aleks G
Jan 3 at 8:32
What about a json_encode an array and writing as a flat file? To read, json_decode it back and voila.
– Kush
Jan 3 at 8:59
Aleks G - I need to be multiplatform window and UNICS. Kush - i can not find a flat file database with support for php files
– bedamusa
Jan 3 at 9:38
add a comment |
Why not use a sqlite database?
– Aleks G
Jan 3 at 8:32
What about a json_encode an array and writing as a flat file? To read, json_decode it back and voila.
– Kush
Jan 3 at 8:59
Aleks G - I need to be multiplatform window and UNICS. Kush - i can not find a flat file database with support for php files
– bedamusa
Jan 3 at 9:38
Why not use a sqlite database?
– Aleks G
Jan 3 at 8:32
Why not use a sqlite database?
– Aleks G
Jan 3 at 8:32
What about a json_encode an array and writing as a flat file? To read, json_decode it back and voila.
– Kush
Jan 3 at 8:59
What about a json_encode an array and writing as a flat file? To read, json_decode it back and voila.
– Kush
Jan 3 at 8:59
Aleks G - I need to be multiplatform window and UNICS. Kush - i can not find a flat file database with support for php files
– bedamusa
Jan 3 at 9:38
Aleks G - I need to be multiplatform window and UNICS. Kush - i can not find a flat file database with support for php files
– bedamusa
Jan 3 at 9:38
add a comment |
3 Answers
3
active
oldest
votes
Probably the best way would be to create a static class which loads the config in the Registry on init. Take a look:
Class Core {
/** @var array $registry Static array for registry variables */
public static $registry = ;
}
Now when you want to load the config, you can just use the Core class:
Core::$registry['config'] = include('./config.php');
And now when you require the config, you can just access the array as follows:
Core::$registry['config'][%your_array_path_for_your_config_item%];
Do know that this can be used for many other things as well, think about saving your dispatches and other runtime variables here as well.
I do not know how things will happen when the values have to change
– bedamusa
Jan 3 at 9:47
add a comment |
The first method is a nice solution. This way you can make multiple config files which are just arrays. If the configuration contains sensitive information you can make use of hidden .env files and in your configuration, you refer to those .env values. This way you can have multiple configurations for multiple environments without changing the config files themselves.
Laravel has a good approach for this problem imho.
https://github.com/laravel/laravel
Example from laravel:
config/databases.php
'sqlite' => [
'driver' => 'sqlite',
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'prefix' => '',
'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
],
The second value of the env() represent a default value. The actual value lives in a .env file which is outside of version control.
I can not work with laravel or other framework
– bedamusa
Jan 3 at 9:44
@bedamusa I am not suggesting you should work with the framework, but simply to use it as an example of how to implement your config setup.
– Christophvh
Jan 3 at 11:30
your idea is to edit only the .env file? - like that
– bedamusa
Jan 3 at 15:01
add a comment |
Does anyone know a Flat File database which uses php files for storage?
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54018725%2fgood-practice-for-choosing-a-web-configuration-file-saved-in-a-php-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Probably the best way would be to create a static class which loads the config in the Registry on init. Take a look:
Class Core {
/** @var array $registry Static array for registry variables */
public static $registry = ;
}
Now when you want to load the config, you can just use the Core class:
Core::$registry['config'] = include('./config.php');
And now when you require the config, you can just access the array as follows:
Core::$registry['config'][%your_array_path_for_your_config_item%];
Do know that this can be used for many other things as well, think about saving your dispatches and other runtime variables here as well.
I do not know how things will happen when the values have to change
– bedamusa
Jan 3 at 9:47
add a comment |
Probably the best way would be to create a static class which loads the config in the Registry on init. Take a look:
Class Core {
/** @var array $registry Static array for registry variables */
public static $registry = ;
}
Now when you want to load the config, you can just use the Core class:
Core::$registry['config'] = include('./config.php');
And now when you require the config, you can just access the array as follows:
Core::$registry['config'][%your_array_path_for_your_config_item%];
Do know that this can be used for many other things as well, think about saving your dispatches and other runtime variables here as well.
I do not know how things will happen when the values have to change
– bedamusa
Jan 3 at 9:47
add a comment |
Probably the best way would be to create a static class which loads the config in the Registry on init. Take a look:
Class Core {
/** @var array $registry Static array for registry variables */
public static $registry = ;
}
Now when you want to load the config, you can just use the Core class:
Core::$registry['config'] = include('./config.php');
And now when you require the config, you can just access the array as follows:
Core::$registry['config'][%your_array_path_for_your_config_item%];
Do know that this can be used for many other things as well, think about saving your dispatches and other runtime variables here as well.
Probably the best way would be to create a static class which loads the config in the Registry on init. Take a look:
Class Core {
/** @var array $registry Static array for registry variables */
public static $registry = ;
}
Now when you want to load the config, you can just use the Core class:
Core::$registry['config'] = include('./config.php');
And now when you require the config, you can just access the array as follows:
Core::$registry['config'][%your_array_path_for_your_config_item%];
Do know that this can be used for many other things as well, think about saving your dispatches and other runtime variables here as well.
answered Jan 3 at 8:45
Harm SmitsHarm Smits
1168
1168
I do not know how things will happen when the values have to change
– bedamusa
Jan 3 at 9:47
add a comment |
I do not know how things will happen when the values have to change
– bedamusa
Jan 3 at 9:47
I do not know how things will happen when the values have to change
– bedamusa
Jan 3 at 9:47
I do not know how things will happen when the values have to change
– bedamusa
Jan 3 at 9:47
add a comment |
The first method is a nice solution. This way you can make multiple config files which are just arrays. If the configuration contains sensitive information you can make use of hidden .env files and in your configuration, you refer to those .env values. This way you can have multiple configurations for multiple environments without changing the config files themselves.
Laravel has a good approach for this problem imho.
https://github.com/laravel/laravel
Example from laravel:
config/databases.php
'sqlite' => [
'driver' => 'sqlite',
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'prefix' => '',
'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
],
The second value of the env() represent a default value. The actual value lives in a .env file which is outside of version control.
I can not work with laravel or other framework
– bedamusa
Jan 3 at 9:44
@bedamusa I am not suggesting you should work with the framework, but simply to use it as an example of how to implement your config setup.
– Christophvh
Jan 3 at 11:30
your idea is to edit only the .env file? - like that
– bedamusa
Jan 3 at 15:01
add a comment |
The first method is a nice solution. This way you can make multiple config files which are just arrays. If the configuration contains sensitive information you can make use of hidden .env files and in your configuration, you refer to those .env values. This way you can have multiple configurations for multiple environments without changing the config files themselves.
Laravel has a good approach for this problem imho.
https://github.com/laravel/laravel
Example from laravel:
config/databases.php
'sqlite' => [
'driver' => 'sqlite',
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'prefix' => '',
'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
],
The second value of the env() represent a default value. The actual value lives in a .env file which is outside of version control.
I can not work with laravel or other framework
– bedamusa
Jan 3 at 9:44
@bedamusa I am not suggesting you should work with the framework, but simply to use it as an example of how to implement your config setup.
– Christophvh
Jan 3 at 11:30
your idea is to edit only the .env file? - like that
– bedamusa
Jan 3 at 15:01
add a comment |
The first method is a nice solution. This way you can make multiple config files which are just arrays. If the configuration contains sensitive information you can make use of hidden .env files and in your configuration, you refer to those .env values. This way you can have multiple configurations for multiple environments without changing the config files themselves.
Laravel has a good approach for this problem imho.
https://github.com/laravel/laravel
Example from laravel:
config/databases.php
'sqlite' => [
'driver' => 'sqlite',
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'prefix' => '',
'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
],
The second value of the env() represent a default value. The actual value lives in a .env file which is outside of version control.
The first method is a nice solution. This way you can make multiple config files which are just arrays. If the configuration contains sensitive information you can make use of hidden .env files and in your configuration, you refer to those .env values. This way you can have multiple configurations for multiple environments without changing the config files themselves.
Laravel has a good approach for this problem imho.
https://github.com/laravel/laravel
Example from laravel:
config/databases.php
'sqlite' => [
'driver' => 'sqlite',
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'prefix' => '',
'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
],
The second value of the env() represent a default value. The actual value lives in a .env file which is outside of version control.
edited Jan 3 at 9:06
answered Jan 3 at 8:54
ChristophvhChristophvh
5,21043549
5,21043549
I can not work with laravel or other framework
– bedamusa
Jan 3 at 9:44
@bedamusa I am not suggesting you should work with the framework, but simply to use it as an example of how to implement your config setup.
– Christophvh
Jan 3 at 11:30
your idea is to edit only the .env file? - like that
– bedamusa
Jan 3 at 15:01
add a comment |
I can not work with laravel or other framework
– bedamusa
Jan 3 at 9:44
@bedamusa I am not suggesting you should work with the framework, but simply to use it as an example of how to implement your config setup.
– Christophvh
Jan 3 at 11:30
your idea is to edit only the .env file? - like that
– bedamusa
Jan 3 at 15:01
I can not work with laravel or other framework
– bedamusa
Jan 3 at 9:44
I can not work with laravel or other framework
– bedamusa
Jan 3 at 9:44
@bedamusa I am not suggesting you should work with the framework, but simply to use it as an example of how to implement your config setup.
– Christophvh
Jan 3 at 11:30
@bedamusa I am not suggesting you should work with the framework, but simply to use it as an example of how to implement your config setup.
– Christophvh
Jan 3 at 11:30
your idea is to edit only the .env file? - like that
– bedamusa
Jan 3 at 15:01
your idea is to edit only the .env file? - like that
– bedamusa
Jan 3 at 15:01
add a comment |
Does anyone know a Flat File database which uses php files for storage?
add a comment |
Does anyone know a Flat File database which uses php files for storage?
add a comment |
Does anyone know a Flat File database which uses php files for storage?
Does anyone know a Flat File database which uses php files for storage?
answered Jan 4 at 18:48
bedamusabedamusa
11
11
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54018725%2fgood-practice-for-choosing-a-web-configuration-file-saved-in-a-php-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Why not use a sqlite database?
– Aleks G
Jan 3 at 8:32
What about a json_encode an array and writing as a flat file? To read, json_decode it back and voila.
– Kush
Jan 3 at 8:59
Aleks G - I need to be multiplatform window and UNICS. Kush - i can not find a flat file database with support for php files
– bedamusa
Jan 3 at 9:38