If you're getting an error that looks like this:
Code:
Warning: session_register(): Cannot send session cookie - headers already sent by (output started at /home/yoursite/public_html/dbconnect.php:12) in /home/yoursite/public_html/common.php on line 1496
This means that somewhere, somehow, your PHP code is sending output to the browser before the session is started. Yeah, I know, technical mumbo jumbo. What do I do to fix it?
The warning you get gives you the information required to locate where the problem is. Let's disect the error:
Code:
Warning: session_register(): Cannot send session cookie - headers already sent by
This part tells you what kind of warning it is. In this case, the HTTP headers have already been sent to the browser. HTTP headers are sent to the browser once the first output is encountered in the script.
Code:
(output started at /home/yoursite/public_html/dbconnect.php:12)
This is the part we're most interested in. It tells us first, that the problem is in the file found at "/home/yoursite/public_html/dbconnect.php" and second that it is at line 12 (note the :12 at the end). This is where we need to look to find the problem.
So edit the file mentioned (in this case, dbconnect.php) and find the appropriate line (in this case 12). See what's going on there that might be causing data to be sent out to the browser. Remember, anything that is found OUTSIDE of the <? and ?> tags in PHP is seen as output.
The MOST common problem here is blank lines at the end of the dbconnect.php file, after the ?> mark. Some text editors will add these lines, which can be a big problem. Use Notepad instead of Word Pad to edit the file. Make sure that there's no blank lines after the ?> mark, and chances are your problems will go away.
Also, you might see problems here if you use echo or print to send data to the browser, such as
Code:
echo "Connected to the database
";
within your dbconnect.php file will cause PHP to whine when it tries to start the session later on.