Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at D:\xampp\htdocs\plaincart\library\config.php:1) in D:\xampp\htdocs\plaincart\library\config.php on line 7

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at D:\xampp\htdocs\plaincart\library\config.php:1) in D:\xampp\htdocs\plaincart\library\config.php on line 7

Hello guys.. Above are the errors that I've encoutered when I started running on my work..

I'm working on my old shopping cart system then I will convert it to enrollment system..

Guys what does the errors located on above is all about? How can I fix them?

And give me some tips on how to create efficient system.. I have 1 week to finish this project. Hope I can do it.. Please help me. Thank you guys and have a nice one. =)

The "headers already sent" error is encountered when you are trying to send a header (usually with the header() function), but that output has already started (usually through echo(), print() or similar, or something outside of PHP).

The reason for the error is that once output has started, you cannot issue further headers. All headers must be sent BEFORE any output.

In your example, it sounds like line 7 of D:\xampp\htdocs\plaincart\library\config.php is trying to send a header() but already at line 1 output has started.

Is there a print or echo statement on line 1?

Did you forget the<?php tag at the beginning of that file?

If you can post the first 10 lines of D:\xampp\htdocs\plaincart\library\config.php we can probably help you more specifically - I'm only making educated guesses.

edwin here's the code, so that you can easily analyze it:

<?php 

ini_set('display_errors', 'On');
//ob_start("ob_gzhandler");
error_reporting(E_ALL);

// database connection config
$dbHost = 'localhost';
$dbUser = 'root';
$dbPass = 'root';
$dbName = 'plaincart';

// start the session
 session_start();

// setting up the web root and server root for
// this shopping cart application
$thisFile = str_replace('\\', '/', __FILE__);
$docRoot = $_SERVER['DOCUMENT_ROOT'];

$webRoot  = str_replace(array($docRoot, 'library/config.php'), '', $thisFile);
$srvRoot  = str_replace('library/config.php', '', $thisFile);

define('WEB_ROOT', $webRoot);
define('SRV_ROOT', $srvRoot);

// these are the directories where we will store all
// category and product images
define('CATEGORY_IMAGE_DIR', 'images/category/');
define('PRODUCT_IMAGE_DIR',  'images/product/');

// some size limitation for the category
// and product images

// all category image width must not 
// exceed 75 pixels
define('MAX_CATEGORY_IMAGE_WIDTH', 75);

// do we need to limit the product image width?
// setting this value to 'true' is recommended
define('LIMIT_PRODUCT_WIDTH',     true);

// maximum width for all product image
define('MAX_PRODUCT_IMAGE_WIDTH', 300);

// the width for product thumbnail
define('THUMBNAIL_WIDTH',         75);

if (!get_magic_quotes_gpc()) {
	if (isset($_POST)) {
		foreach ($_POST as $key => $value) {
			$_POST[$key] =  trim(addslashes($value));
		}
	}
	
	if (isset($_GET)) {
		foreach ($_GET as $key => $value) {
			$_GET[$key] = trim(addslashes($value));
		}
	}	
}

// since all page will require a database access
// and the common library is also used by all
// it's logical to load these library here
require_once 'database.php';
require_once 'common.php';

// get the shop configuration ( name, addres, etc ), all page need it
$shopConfig = getShopConfig();

?>

edwin here's the code, so that you can easily analyze it:
...

Something doesn't add up. The error reported is on line 7 but in the code that you posted, line 7 is nothing - just a comment.

Are you sure this is the code that's running on your Web server? Have you tried re-uploading it?

As I said, line 7 reads: // database connection config so clearly there cannot be an error there. Line 14 looks more suspect but is a different line number from that reported in the error message which is what makes me think your server has different content to what you've posted here.

yes i've tried to put session_start() in different lines then check if there's no more error actually session_start() is actually on line 7 a while ago. I just moved it to another line...

actually session_start is always highlighted as an error wherever when i move it to another line at a time.

Is there anything between the start of the file and <?php (like a space, new line, or something)?

Seems strange that the error message is reporting output on line 1... it's almost as if you have a space at the beginning, like this:

<?php
blah blah blah

or a new line, like htis:

<?php
blah blah blah

i've already solved the issue by reinstalling again the whole folder system thank you for your time.. yah i've also tried that.. but i think the problem that i've encounter is that i use microsoft web expression.. rather than notepad that makes the files too heavy i think..

i've already solved the issue by reinstalling again the whole folder system thank you for your time.. yah i've also tried that.. but i think the problem that i've encounter is that i use microsoft web expression.. rather than notepad that makes the files too heavy i think..

Ah - I suspect it was putting certain characters before the <?php open tag.

Yes, you really do need to be using a plain text editor such as TextWrangler or even just Notepad.

You most likely had a problem with the file being encoded in UTF-8.  is usually the sign of this. For some reason there is a special character that sometimes is put at the beginning of the file.

Guys can you give me more tips how to create an ideal enrollment system actually i have here an old php system in e commerce and i want to convert it to enrollment system.. Hope you could help me more about this details.. If you have sample ERD in enrollment system in high school kindly give me the link so I can analyze it out. Thank you guys..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.