Is there a way to use session_start(); at the top of a php page, and still be able to use header statments in the same php page later on? without getting those nasty headers already sent error messages?
You can use as many different header type statements as you want (session_start(), setcookie(), header()...) as long as all of them come before any output is generated (whether via echo, e.g., or text not within <?php...?> tags). If you find yourself simply unable to organize your script in such a way to avoid any output, you can use the output buffering functions, but this may add a bit of overhead to things.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
You can use as many different header type statements as you want (session_start(), setcookie(), header()...) as long as all of them come before any output is generated (whether via echo, e.g., or text not within <?php...?> tags). If you find yourself simply unable to organize your script in such a way to avoid any output, you can use the output buffering functions, but this may add a bit of overhead to things.
Thanks for the reply NogDog. I had it set up so that the one echo statement was at the very bottom, but, I'm wondering if "PDF_show_xy" qualifies as an "output" type statement? Because that's the only thing I can see that's possibly creating output and that is above the "header" statements.
I'll research the 'output buffering' functions too - I didn't know about those...
The 3 header statements that I have at the bottom of my file, just above the one echo statement are:
Thanks for the reply NogDog. I had it set up so that the one echo statement was at the very bottom, but, I'm wondering if "PDF_show_xy" qualifies as an "output" type statement? Because that's the only thing I can see that's possibly creating output and that is above the "header" statements.
I'll research the 'output buffering' functions too - I didn't know about those...
The 3 header statements that I have at the bottom of my file, just above the one echo statement are:
Which work okay, until I put in the "session_start();" at the very top. Then I get headers already created type errors.
I would like to know which headers the "session_start();" sets.
I managed to get my page working this evening. I had to move things around
and play with it a little bit. But, then I got to the point where ff was working well, but IE was giving me some nasty error msg. to the effect that it wasn't finding my page. I put in a "session_cache_limiter('public');" statement just before the "session_start();" - and voilą! it works! I'm guessing that session_start sets the cache in some way that IE didn't like...
session_start() sets a cookie header (the same as setcookie() does) to hold the session ID.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
session_start() sets a cookie header (the same as setcookie() does) to hold the session ID.
Thanks, I didn't know that. Is that all that it sets?
It seems like IE7 has some problem with this session_start in this file. I use it all the time in all my other pages, with no
issues. So, today I've got to research the 'session_cache_limiter' and see why certain settings work, like 'public' and 'private', but the one I prefer, 'nochache' doesn't work right for me, with this page. In testing, I found that 'public' was not refreshing - ever, and I need it to refresh at each new request (in IE). FF seems to be working fine either way...
It looks like 'session_cache_limiter ("must-revalidate");' is working much better for me. The page displays - #1 and #2, it refreshes properly displaying new content each time... Still testing, but it's looking much better... Good in FF too!
Thank You redtail for posting this! I would have never figured this out. I just registered to post this.
You're welcome! Glad it helped you. I had a heck of a time with this one...And usually, if I'm having a hard time with something, other folks will be too...
Bookmarks