Session is not getting maintain in settings.php drupal 7 I have Created one php file on root of drupal7 and access it using URL.I have one form in that file which has dropdown values and submit button. Now in settings.php i am getting those value in POST. Based on That post value i want to select DB for drupal. But it Throws error because session is not getting maintain.
This is my code in settings.php

session_start();
$_SESSION['data'] = $_POST['year'];
if(!empty($_SESSION['data'])) {
  $databases = array (
    'default' =&gt;
       array (
        'default' =&gt;
          array (
            'database' =&gt; 'mydbname'.$_SESSION['data'],
            'username' =&gt; 'root',
            'password' =&gt; '',
            'host' =&gt; 'localhost',
            'port' =&gt; '',
            'driver' =&gt; 'mysql',
            'prefix' =&gt; '',
          ),
      ),
  );
}
else {
  header("Location: welcome.php");
}
You can't start session_start() the second time, since Drupal is already started it.

So either remove it, or wrap it into the condition, e.g.:

if (session_status() == PHP_SESSION_NONE) {
    session_start();
}


Parsing input user variables is not a good idea, so it's better if filter it out, e.g.

$_SESSION['data'] = filter_input(INPUT_POST, 'year', FILTER_SANITIZE_STRING);


or better use db_escape_table().