How do I use variables from config.ini.php? I have a config.ini.php file as follows :

;&lt;?php
;die(); // For further security
; // These php lines are used to hide the data from the browser
; // They are both valid php and valid ini files
;/*
; Don't forget to disable and reenable module, after adjusting the values
[folders]
var_1= "value1"
var_2 = "value2"


And in module_name.install file, I am using it as follows.

/**
 * Implementation of hook_enable().
 */
function module_name_enable() {
  $config_file = 'config.ini.php';
  $parameters = parse_ini_file($config_file);
  foreach ($parameters as $key =&gt; $value) {
    \Drupal::state()-&gt;set($key, $value);
    \Drupal::config('module_name.settings')
      -&gt;set($key, $value)
      -&gt;save();
  }
}


I then try to use a variable with the following code.

$getvar = \Drupal::config('module_name.settings')
      -&gt;get('var_1'); 
\Drupal::state()-&gt;get('var_1', '');


I am not getting the value. What am I doing wrong?
As far as I know, you shouldn't be using a "config.ini.php" file for configs in your custom module.

You should have a /examplemodule/config/install/examplemodule.settings.yml file like this:

var_1: "value1"
var_2: "value2"


Then when you reinstall your module, it adds the values.  There's no need to run code in hook_install.

To access the values, use:

\Drupal::config('examplemodule.settings')-&gt;get('var_1');


and to edit:

\Drupal::configFactory()
  -&gt;getEditable('examplemodule.settings')
  -&gt;set('var_1', $value)
  -&gt;save();


You're using state correctly, I tested this out:

\Drupal::state()-&gt;set('var_1', $value);

$var_1 = \Drupal::state()-&gt;get('var_1');