
- You are not logged in. | Login
November 14, 2006 8:34 pm
- IBdaMac
- Member


php session problem
Hi, I have a problem using 'sessions' in PHP, can someone help me?
I have a website where I want to allow users to login to post images and files, but when I try my login script I'm getting this error:
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by ...
and the session doesn't work. Please help!
November 14, 2006 8:45 pm
- phppat
- Member


Re: php session problem
This is a pretty common problem for people starting out with PHP sessions.
This is almost always caused by some other output before the 'session_start()' function in your script, either html, a php print or echo statement, or even whitespace in some cases.
You should be sure that there is *nothing* outputted before the session_start() function. The easiest fix is usually starting the session first, before any other PHP or HTML, for example:
<?php session_start(); .... other PHP code --- ?> <html> <body> ... other HTML code ... </body> </html>
Again, be certain there is no whitespace before the opening tag, as some webservers may try to output the spaces it to the browser before running the PHP code.
Hope that helps!
-- PHPPat
Last edited by phppat (November 14, 2006 8:47 pm)
PHP monster
November 14, 2006 9:09 pm
- IBdaMac
- Member


Re: php session problem
Thanks, that was it!
I had my html tag before the php code, and now it works!
Last edited by IBdaMac (November 14, 2006 9:11 pm)


