title: PHP - Session already started - ignoring session_start (but doesn't do just that)
body: <p>Does anyone have an explanation for what is going on here?</p>
  
  <p>I have a mainpage, on which I call <code>session_start()</code>.
  Then I have an PHP script, which is invoked using Ajax.
  If I don't put in <code>session_start()</code> there, it will not work.
  However, if I do, it works just fine, but displaying: </p>
  
  <blockquote>
    <p>Notice: A session had already been started - ignoring session_start() in C:\xampp\htdocs\dsb\php\ds_acc.php on line 2</p>
  </blockquote>
  
  <p>I probably have made a mistake somewhere, but isn't that a paradox? While saying, it ignores that <code>session_start()</code>, the script breaks when removing it.
  Thank you for your input.</p>
  
  <p>Here the code, sorry if it is a bit obfuscated:</p>
  
  <p>index.php:</p>
  
  <pre><code>&lt;?php
    session_start();
    require_once("php/ds_acc.php");
  ?&gt;
  </code></pre>
  
  <p>ds_acc.php:</p>
  
  <pre><code>&lt;?php
  session_start();
  
  require_once("db_login.php");
  require_once("permission.php");
  
  if(check_permission("user"))
  {   
      if(isset($_REQUEST["action"]))
      {
          switch($_REQUEST["action"])
          {
              case "add":
              add_user();
              break;
          }
      }
  }else
  {
      echo "error: session invalid";
  }
  
  function add_user()
  {
  }
  ?&gt;
  </code></pre>
  
  <p>permission.php:</p>
  
  <pre><code>&lt;?php
  require_once("db_login.php");
  /* Returns true if permission is granted, otherwise false. */
  
  function check_permission($required_level)
  {
      if(!isset($_SESSION["id"]))
      {
          /* Not logged in */
          return false;
      }
  
      /* reload banned */
      $con = get_con();
      $stmt = $con-&gt;prepare("SELECT banned FROM users WHERE id = ?");
      $stmt-&gt;bind_param("i", $_SESSION["id"]);
      $stmt-&gt;execute();
      $stmt-&gt;bind_result($banned);
      $stmt-&gt;fetch();
      $stmt-&gt;close();
      $con-&gt;close();
  
      if($banned == 1)
      {
          $_SESSION = array();
          session_destroy();
          return false;
      }
  
  
      if($_SESSION["permission"] == "admin")
      {
          return true;
      }
  
      switch($required_level)
      {
          case "user":
              return true;
          case "mod":
              return ($_SESSION["permission"] == "mod");
          default:
              return false;
      }
  }
  ?&gt;
  </code></pre>
  
  <p>At the time of copying, I now realized that it probably is connected to me including the ds_acc.php file to use it's functions, while also using it to post data via Ajax. I should do that in separate files. </p>
  
  <p>(Well, nvm, stackoverflow does not like php starting tags apparently)
  Btw, took me a lot of time to format the code before it let me post it, because the first <code>&lt;?</code> in one of my files was intended only 3 spaces <code>._.</code></p>