'I can't start xero oauth session in wordress plugin

I am trying to connect users xero accounts with my app and I have that problem

Warning: session_start(): Cannot start session when headers already sent in /storage.php on line 11

my storage.php is like :

<?php
class StorageClass
{
    function __construct() {
        if( !isset($_SESSION) ){
            $this->init_session();
        }
    }

    public function init_session(){
        session_start();
    }

    public function getSession() {
        return $_SESSION['oauth2'];
    }

    public function startSession($token, $secret, $expires = null)
    {
        session_start();
    }

    public function setToken($token, $expires = null, $tenantId, $refreshToken, $idToken)
    {
        $_SESSION['oauth2'] = [
            'token' => $token,
            'expires' => $expires,
            'tenant_id' => $tenantId,
            'refresh_token' => $refreshToken,
            'id_token' => $idToken
        ];
    }

    public function getToken()
    {
        //If it doesn't exist or is expired, return null
        if (empty($this->getSession())
            || ($_SESSION['oauth2']['expires'] !== null
            && $_SESSION['oauth2']['expires'] <= time())
        ) {
            return null;
        }
        return $this->getSession();
    }

    public function getAccessToken()
    {
        return $_SESSION['oauth2']['token'];
    }

    public function getRefreshToken()
    {
        return $_SESSION['oauth2']['refresh_token'];
    }

    public function getExpires()
    {
        return $_SESSION['oauth2']['expires'];
    }

    public function getXeroTenantId()
    {
        return $_SESSION['oauth2']['tenant_id'];
    }

    public function getIdToken()
    {
        return $_SESSION['oauth2']['id_token'];
    }

    public function getHasExpired()
    {
        if (!empty($this->getSession()))
        {
            if(time() > $this->getExpires())
            {
                return true;
            } else {
                return false;
            }
        } else {
            return true;
        }
    }
}

and I call that class from

<?php
  ini_set('display_errors', 'On');
  require __DIR__ . '/vendor/autoload.php';
  require_once('storage.php');
   // Storage Class uses sessions for storing access token (demo only)
  // you'll need to extend to your Database for a scalable solution
  $storage = new StorageClass();
  $provider = new \League\OAuth2\Client\Provider\GenericProvider([
    'clientId'                => '*********************************',
    'clientSecret'            => '*********************************',
    'redirectUri'             => '*********************************',
    'urlAuthorize'            => 'https://login.xero.com/identity/connect/authorize',
    'urlAccessToken'          => 'https://identity.xero.com/connect/token',
    'urlResourceOwnerDetails' => 'https://api.xero.com/api.xro/2.0/Organisation'
  ]);

It is working fine in my localhost but when I upload the plugin in the host it give me that error.

Thanks for you time.



Solution 1:[1]

Thanks for all of you for your interest. the answer was in 'output_buffering' I set it to on in .user.ini file to override php.ini and I put it in the public_html directory. Thanks again @droopsnoot.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ahmed Zidan