Thanks for your help!
You were right with your first post, I had just written the script in such a way that it wasn't amediately apparent.
I fixed it so that the session call and header functions were the first part of the script to execute. Now it works without a problem.
I still don't know...