Hi,

I have almost finished my first webpage with php but I have an error I can't manage to fix.

I used the plaincart template to start with.

If you go to www.michton.com/shop.php

There is an error at the top of the page, it is on black so you need to highlight it.

The error is:

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/mark1471/public_html/shop.php:6) in /home/mark1471/public_html/library/config.php on line 3

Does anyone know how to fix this.

I'm not sure what information would help but I've inluded some code below.

Thanks in advance

shop.php

<?php
require_once 'library/config.php';
require_once 'library/category-functions.php';
require_once 'library/product-functions.php';
require_once 'library/cart-functions.php';
$_SESSION['shop_return_url'] = $_SERVER['REQUEST_URI'];
$catId = (isset($_GET['c']) && $_GET['c'] != '1') ? $_GET['c'] : 0;
$pdId = (isset($_GET['p']) && $_GET['p'] != '') ? $_GET['p'] : 0;
require_once 'include/header.php';
?>

config.php

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

// start the session
session_start();

// database connection config
$dbHost = 'localhost';
$dbUser = 'mark1471_michton';
$dbPass = 'nottelling;
$dbName = 'mark1471_plaincart';

// 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 220 pixels
define('MAX_CATEGORY_IMAGE_WIDTH', 110);

// 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', 110);

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();
?>


Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/mark1471/public_html/shop.php:6) in /home/mark1471/public_html/library/config.php on line 3

If you try to call session_start() after any content has been output to the page, you will get this error. Make sure that none of your included files are outputting any content to the page such as with an echo or print statement BEFORE you call session_start. Also, it could be as simple as blank lines following your closing PHP tag in any of your includes...such trailing whitespace gets output to the page at the end of each include--eliminate it if it exists.

It is usually a good idea to put the session_start() call as your topmost declaration whenever possible, or to use the output buffer to flush all output to the browser at once. output buffering is an advanced topic, but you can learn more about it here.

The other pages it refers to start

<?php
require_once 'config.php';

Could this be the problem

where is session_start in shop.php ?

There isn't one, should there be?

yep.. You should have session_start on top of every page which uses session/session variable.

Hi, I have moved it to the top of each page and still no luck.

check if you are echoing anything or having any html tags before calling a header function.

at the top of your config.php you start output buffering, but have commented it out:

//ob_start("ob_gzhandler");

that probably means that the script sends headers throughout it...you may want to turn output buffering back on, otherwise you may be hunting down headers, echo statements, and whitespace until you're ready to pull your hair out and the script doesn't work anymore.

you can learn more about ob_gzhandler here: http://us.php.net/manual/en/function.ob-gzhandler.php

or you may just want to replace it with a plain old ob_start() call at the start, and an ob_end_flush() at the end of your scripts.

It works.

Thank you for all your help.

I have other code before the php section on the shop page.

Now it works a treat.

I have problem with this code.. my browser prints:
Fatal error: Call to undefined function mysql_connect() in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\plaincart\library\database.php on line 4

i have some problem with this code...
my browser prints..

i have problem with database line 4...

$thisFile = str_replace('\\', '/', __FILE__);
$docRoot = $_SERVER;

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

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.