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;
}







-1















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.










share|improve this question

























  • 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




















-1















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.










share|improve this question

























  • 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
















-1












-1








-1








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.










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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





















  • 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














3 Answers
3






active

oldest

votes


















0














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.






share|improve this answer
























  • I do not know how things will happen when the values have to change

    – bedamusa
    Jan 3 at 9:47



















0














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.






share|improve this answer


























  • 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



















0














Does anyone know a Flat File database which uses php files for storage?






share|improve this answer
























    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
    });


    }
    });














    draft saved

    draft discarded


















    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









    0














    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.






    share|improve this answer
























    • I do not know how things will happen when the values have to change

      – bedamusa
      Jan 3 at 9:47
















    0














    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.






    share|improve this answer
























    • I do not know how things will happen when the values have to change

      – bedamusa
      Jan 3 at 9:47














    0












    0








    0







    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.






    share|improve this answer













    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.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    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



















    • 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













    0














    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.






    share|improve this answer


























    • 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
















    0














    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.






    share|improve this answer


























    • 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














    0












    0








    0







    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.






    share|improve this answer















    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.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    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



















    • 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











    0














    Does anyone know a Flat File database which uses php files for storage?






    share|improve this answer




























      0














      Does anyone know a Flat File database which uses php files for storage?






      share|improve this answer


























        0












        0








        0







        Does anyone know a Flat File database which uses php files for storage?






        share|improve this answer













        Does anyone know a Flat File database which uses php files for storage?







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 4 at 18:48









        bedamusabedamusa

        11




        11






























            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            How to fix TextFormField cause rebuild widget in Flutter

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith