Somewhat similar.
Normally you send something (whether or not you know it, but each time you make an http connection you send something) like the following:
POST /cgi-bin/log.cgi HTTP/1.0
Host: www.livejournal.com
Content-type: application/x-www-form-urlencoded
Content-length: 34
mode=login&user=test&password=test
now, that is for a form being sent, but the same idea applies to html being sent.. and that first block of text is called the headers.. they must be sent first, once those are sent, then your data (in your case, the html file) is sent..
so what you are trying to do, is set a value that should be with the headers, after they have been sent (and set).. not legal 🙁
so any of your session info must be put towards the top of your file, before really anything else..
(if i've got my thinking cap on right that is.)
-ken