The code doesn't have to be substantial, a simple <html> at the top of your document before the cookies will mess things up! You should always include your cookies BEFORE any code is sent to the browser.
So remember this if you are having trouble with cookies working on your website: Cookies Before Code!

