ActiveCampaign / activecampaign-api-php

MIT License
115 stars 76 forks source link

Warning Error: Cannot modify header information #28

Closed prashant-earth closed 7 years ago

prashant-earth commented 8 years ago

Hi,

We are using your activecampaign library and we want to print details about the result from API calls. And as the library uses HTTP POST headers to make calls, we get notice error : Warning Error: Cannot modify header information - headers already sent

How can we resolve this issue?

Thanks

mthommes commented 8 years ago

Hi, we already provide a debugging mechanism that outputs the full request details. Just do this before calling api():

$ac->debug = true;

Otherwise, anywhere in Connector.class.php you can output debug statements like this:

$this->dbg("my debug stuff");

Hope that helps!

dieend commented 8 years ago

@prashant-earth try commenting this line https://github.com/ActiveCampaign/activecampaign-api-php/blob/master/includes/Connector.class.php#L205

prashant-earth commented 8 years ago

@dieend Instead of commenting that line can you make following change to the library so that the change is hosted at activecampaign library itself and does not get removed with composer updates. And it will be available to everyone.

This fix will NOT send headers when the invocation is from Command Line Interface.

    $php_sapi = php_sapi_name();
    if($php_sapi !== 'cli'){ 
        header("HTTP/1.1 " . $http_code);
    }
dieend commented 8 years ago

I've actually done that before commenting here. See https://github.com/ActiveCampaign/activecampaign-api-php/pull/30 @prashant-earth You can vote there to make this repo maintainer merge it.

prashant-earth commented 8 years ago

@dieend Ok, thanks!