Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Output already started

Guest
Mar 06, 2010 Mar 06, 2010

Copy link to clipboard

Copied

Thank you for taking the time to respond.

While I have you on the line can I ask another PHP question?

I call a header file from an index file. In the first code snippet I get the "output already started" when I run the index page. In the second I don't.

<?php

session_start();

require_once ('db_connect_lms.php'); // include the database connection

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

---------------------------------------------------------------------------------------------------------------------------------

<?php

error_reporting(0);

session_start();

require_once ('db_connect_lms.php'); // include the database connection

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

If I comment my error check out, which I did after my dbase connection worked, I got the error. Even removing the line completely causes the same error. I thought the parser was seeing it as a blank line.

I am new to PHP but thought I had this part figured out. Can you explain why the error occurs?

TOPICS
Server side applications

Views

891
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 06, 2010 Mar 06, 2010

Copy link to clipboard

Copied

I have branched this into a separate thread. Please keep to one subject per thread. It makes it easier for everyone to follow.

The problem with output already started is probably caused by whitespace in your connections file. See the following article for a detailed explanation of the most frequent causes: http://kb2.adobe.com/community/publishing/505/cpsid_50572.html.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 06, 2010 Mar 06, 2010

Copy link to clipboard

Copied

Here is my connection file code:

<?php
define("HOST", "localhost");
# Database user
define("DBUSER", "root");
# Database password
define("PASS", "J1s2m3");
# Database name
define("DB", "my_lms");
# Make the mysql connection
$conn = mysql_connect(HOST, DBUSER, PASS) or  die('Could not connect !<br />Please contact the site\'s administrator.');
$db = mysql_select_db(DB) or  die('Could not connect to database !<br />Please contact the site\'s administrator.');
?>

The <?php at the top is line 1.

There is no whitespace after the ?>, as there are no line numbers (great tip!). I am stumped if the problem is in here.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 06, 2010 Mar 06, 2010

Copy link to clipboard

Copied

What does the error message actually say? It should tell you where the ouput began.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 06, 2010 Mar 06, 2010

Copy link to clipboard

Copied

Warning: session_start() [

function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\mylms\index.php:3) in C:\xampp\htdocs\mylms\header_lms.php on line 3.

This is with the code like the second snippet above. To me it's pointing to the sessionstart().

If I remove the //error_reporting(0); line completly, it points to line two, again the sessionstart().

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 06, 2010 Mar 06, 2010

Copy link to clipboard

Copied

ThusSpakeZarathustra wrote:

Warning: session_start() [

function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\xampp\htdocs\mylms\index.php:3) in C:\xampp\htdocs\mylms\header_lms.php on line 3.

Look at the names of the files. The output started in index.php, but the error message is reporting that the problem is in header_lms.php. In other words, you're including index.php in header_lms.php.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 06, 2010 Mar 06, 2010

Copy link to clipboard

Copied

I appreciate you taking the time to answer. I am not sure what you mean by I have included the index file in the header file or how exactly I have done that. I have just started the project so I’ve included the (minimal) code for the two files.

After writing the above and more playing I moved the first line (<!DOCTYPE HTML PUBLIC…) to follow the code and it works. I guess I still need a better understanding of relative placement of code in a file. I’ll re-read again.

You have already taken a lot of time with me but could you explain why leaving the line in the wrong place in the index file but uncommented out the error_reporting(0); line in the header file eliminates the warning? Again, it been very kind of you to help!

This is the index file.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<?php

require_once ("header_lms.php");

include ("login_lms.php");

require_once ("footer_lms.php");

?>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title>index page</title>

</head>

<body>

<?php

echo "HERE!";

?>

</body>

</html>

This is the header file.

<?php

//error_reporting(0);

session_start();

require_once ("db_connect_lms.php");

require_once ("functions.php");

$domain =  "abc123.com"; ?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<title>Complete Member Login / System tutorial - <?php echo $domain; ?></title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>

<body>

<h1>header_lms</h1>

</body>

</html>

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 06, 2010 Mar 06, 2010

Copy link to clipboard

Copied

Now that I have seen your code, it's perfectly obvious what's wrong. When I pointed you to the article about output already sent, I assumed you understood the meaning of "output". Obviously, I assumed too much, and I have amended the article accordingly.

"Output" means anything sent to the browser. This includes things like the DOCTYPE declaration.

The other thing that you have misunderstood is how server-side includes work.

A page using server-side includes (or PHP include files) is like a jigsaw puzzle. When all the pieces are put together, they should fit perfectly with nothing left over. A web page has one DOCTYPE declaration, one html element, one head, and one body. Include files should be snippets that slot into the overall whole. An include should not have a DOCTYPE declaration, and if you're including things like headers and footers, they should be included at the point where they slot into the page, not at the top.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 06, 2010 Mar 06, 2010

Copy link to clipboard

Copied

LATEST

I thought the PHP code should be before anything else. Looking back at earlier saved version when I moved the doctype line to the first line and at the same time uncommented the line I mentioned (in above post) in the header file and the warning vanished made me think doctype need to be the first line. The fact that I am also new to Dreamweaver and every time you start a new php page it places the dctype line first I mistook as required “somewhere” in any php file.

You are right about not understanding the way includes work on the web. Your explanation helps and makes perfect sense.

Sorry if my slow uptake was frustrating. You were very patient and helped a great deal. Thanks again!

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines