title: ignoring session_start() & getallheaders() error Opencart
body: <p>I'm running RestAPI on Opencart 1.5.2.1, the server runs PHP Version 7.1.19 and Server API FPM/FastCGI over Apache. I'm facing issues with session, I have a VQMOD xml file installed to add certain functions to the system session of Opencart.</p>
  
  <p>Please let me share the whole session code first:</p>
  
  <pre><code>  &lt;file name="system/library/session.php"&gt;
     &lt;operation&gt;
        &lt;search  position="before"&gt;&lt;![CDATA[
            if (!session_id()) {
        ]]&gt;&lt;/search&gt;
        &lt;add&gt;&lt;![CDATA[
            $token_array = json_decode(file_get_contents("php://input"),true);
  
            if (isset($token_array['ic_token'])) {
            $ic_token = $token_array['ic_token'];
            } elseif(isset($_POST['ic_token'])){
            $ic_token = $_POST['ic_token'];
            }
  
            if (isset(getallheaders()['ic_token'])) {
            $ic_token = getallheaders()['ic_token'];
            } elseif (isset(getallheaders()['Ic-Token'])) {
            $ic_token = getallheaders()['Ic-Token'];
            }
  
            if (isset($ic_token) &amp;&amp; $ic_token != 'Session_Not_Loggin') {
            session_id($ic_token);
            session_start();
            }
        ]]&gt;&lt;/add&gt;
      &lt;/operation&gt;
  &lt;/file&gt;
  </code></pre>
  
  <p>When calling a function using Postman I first get an error</p>
  
  <blockquote>
    <p>Fatal error: Uncaught Error: Call to undefined function
    getallheaders() in
    /var/www/vhosts/example.com/httpdocs/vqmod/vqcache/vq2-system_library_session.php:15
    Stack trace: #0
    /var/www/vhosts/example.com/httpdocs/admin/index.php(110):
    Session->__construct() #1 {main} thrown in
    /var/www/vhosts/example.com/httpdocs/vqmod/vqcache/vq2-system_library_session.php
    on line 15</p>
  </blockquote>
  
  <p>I googled and found that PHP-FPM doesn't support getallheaders() I tried a workaround but didn't work. I've removed the code from the xml code and became like that:</p>
  
  <pre><code>      &lt;file name="system/library/session.php"&gt;
         &lt;operation&gt;
            &lt;search  position="before"&gt;&lt;![CDATA[
                if (!session_id()) {
            ]]&gt;&lt;/search&gt;
            &lt;add&gt;&lt;![CDATA[
                $token_array = json_decode(file_get_contents("php://input"),true);
  
                if (isset($token_array['ic_token'])) {
                $ic_token = $token_array['ic_token'];
                } elseif(isset($_POST['ic_token'])){
                $ic_token = $_POST['ic_token'];
                }
  
  ==&gt; the getallheaders() code has been removed
  
  
  
                if (isset($ic_token) &amp;&amp; $ic_token != 'Session_Not_Loggin') {
                session_id($ic_token);
                session_start();
                }
            ]]&gt;&lt;/add&gt;
          &lt;/operation&gt;
      &lt;/file&gt;
  </code></pre>
  
  <p>This has caused a new error:</p>
  
  <blockquote>
    <p>Notice: A session had already been started - ignoring session_start()
    in
    /var/www/vhosts/example.com/httpdocs/vqmod/vqcache/vq2-system_library_session.php
    on line 19</p>
  </blockquote>
  
  <p>Please not I tried this workaround</p>
  
  <pre><code>          if (!function_exists('getallheaders'))
            {
              function getallheaders()
              {
                if (isset(getallheaders()['ic_token'])) {
                $ic_token = getallheaders()['ic_token'];
                } elseif (isset(getallheaders()['Ic-Token'])) {
                $ic_token = getallheaders()['Ic-Token'];
                };
              };
             };
  </code></pre>
  
  <p>This is giving me 503 Service Unavailable "Unexpected '&lt;'"</p>
  
  <p>Any help please, highly appreciated.</p>