Using PHP Sample code receiving error: Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by ??
AnsweredI'm trying to setup a PHP test page that will just authenticate.
Code in HTML page is very simple.
<?php
// Include the config file and the Podio library
require_once 'config.php';
require_once 'PodioAPI.php';
// Setup the API client reference. Client ID and Client Secrets are defined
// as constants in config.php
Podio::setup(CLIENT_ID, CLIENT_SECRET);
?>
All the supporting libraries were just pulled and uploaded in the root folder.
I can't seem to resolve the error:
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/content/36/10438736/html/index.php:9) in /home/content/36/10438736/html/lib/PodioSession.php on line 7
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/content/36/10438736/html/index.php:9) in /home/content/36/10438736/html/lib/PodioSession.php on line 7
Any ideas?
-
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 -
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.
-
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
-
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
Please sign in to leave a comment.
Comments
5 comments