session_start(); used with other headers?
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.
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.
Originally Posted by NogDog
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:
header('Content-disposition: inline; filename=Test.pdf');
header('Content-length: ' . strlen($data));
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.
Originally Posted by redtail
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...
Anyway, it's working...
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?
Originally Posted by NogDog
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...
Originally Posted by sammylightfoot
Please do the same for someone else, sometime.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)