You have to send the header information before sending anything else.
If you are using cookies to track your PHPSESSID then you can simply go ahead and do this and your session will remain intact.
If you are NOT using cookies and are instead tracking your session by passing the PHPSESSID through the URLs simply add it to the end of your location like so:
header ("Location: nextpage.php?PHPSESSID=$PHPSESSID");
Happy Codin! =)
- nutter