Using PHP Sample code receiving error: Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by ??

Answered

Comments

5 comments

  • Andreas Haugstrup Pedersen

    You are sending output to the browser before starting the session and that will not work. The PHP library automatically starts a simple session manager for you, so it's running session_start for you.

    Solution: Get rid of any output before the call to Podio::set()

    All the best,

    Andreas 

    0
    Comment actions Permalink
  • Sean MacGillivray

    I am hitting this same wall as well and am not clear on your answer; do you mean that the podio API must be called before PHP outputs anything to the browser, or before anything at all including HTML outside PHP tags? I don't see anything in the example code the OP provided besides two includes and the instantiation of the API, nothing is output to the browser before the API session call. 

    0
    Comment actions Permalink
  • Andreas Haugstrup Pedersen

    Hi Sean,

    This is how all sessions work and it's not an issue specific to podio-php. If you are using sessions (and by default podio-php is using sessions to store the auth tokens for you), you cannot have any output before the session is started. In the case of podio-php you cannot have any output (HTML, whitespace, anything) before you call Podio::setup()

    Does that help? Googling the error message will give you lots of discussion about this topic since it's a common issue for people who are just starting out with PHP and sessions.

    /Andreas

    0
    Comment actions Permalink
  • Sean MacGillivray

    Hi Andreas,

     

    Thanks for the clarification, I was just confused I think by the brevity of the code the OP provided. I move my podio::setup call to the beginning of the page in question and that resolved my issue. One thing I came across in my reading about sessions that other developers may find helpful is that the call to the session function has to happen in the first set of <?PHP tags in the document; ending with a ?> and starting another <?PHP, even if nothing is explicitly output to the browser in the first set of tags, counts as "output"  and will snarl the session call. 

     

    much obliged for the help!

     

    Sean

    0
    Comment actions Permalink
  • Andreas Haugstrup Pedersen

    No problem, feel free to ask if you run into other issues.

    All the best,

    Andreas

    0
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk